Thanks for the information there Dimitry and Chuck. I forgot to add one thing in my post. The form I am talking about is a form that has been created by a developer to assist automated testing. In real world, users of our website will see a promotion somewhere(let's say google). When one clicks on that advertisement it will bring the user to our website with the promotion code filled in and letting the users fill the rest of the form to be able to register and claim the promotion. So the form here is a HTML page written by a developer so that when I click on the button in the form it will do the same thing as in the real world when a customer clicks on a promotion on Google. I actually don;t have the HTML of the form handy but I can paste it on Monday when I get back to work. So basically my question was to whether I can define that <form> </form> in my Page and use it with the page object to post it and give me the website page filled with the promotion code just like the user would do actually. On 6 Aug 2011, at 12:17, Chuck van der Linden wrote:
> Be aware that doing stuff like this with forms at the HTTP level can > get very tricky. You generally must first establish a session with > the webserver, then capture specific data regarding the session, and > potentially other things like 'viewstate' and be able to include them > along with the form data in your response. > > Using a value from earlier won't work as that session will usually > have expired, you almost always have to capture and extract the stuff > you need on the fly. (you'll get really good at regular expressions, > trust me) > > Technically, this is close to 'spoofing' and thus there are many > security measures (like viewstate) that are designed to prevent > spoofing that will trip you up unless you do it exactly right. This > kind of stuff requires either a pretty in-depth knowledge of HTTP and > how webservers maintain state and sessions, or a good tool that will > do a lot of things for you. (the 'webtest' tools built into the > latest version of visual studio (if you are .net folks) is actually > pretty good at doing stuff like this at the protocol level, especially > if your site is done in .net. ) > > On Aug 5, 12:40 pm, Dmitriy Korobskiy <dkro...@gmail.com> wrote: >> On 8/5/11 6:04 AM, Rahul Sharma wrote:> I have already tried >> Net::HTTP.post_form but I guess it only works for >>> forms that are on some page. >> >> Rahul, >> >> when a form is posted, the POST data in the request body contains only >> pairs of HTTP-encoded form fields: NAME=VALUE >> >> That *might* be all you need. It does not matter much where the original >> page is located keeping in mind the following two caveats: >> >> 1. Your target page might or might not be checking HTTP_REFERRER value >> in the request's HTTP headers. HTTP_REFERRER contains the URL of the >> original page, >> and it should be easy to put it in when you assemble your request >> "manually" in your code. >> >> 2. Your browser session typically contains session and maybe even >> persistent cookies that keep track of (logged in) user session and get >> submitted with each request. If you capture cookies, >> you can put them into your request. >> >> I hope it helps. >> >> -- >> DK >> AIM: DKroot1, Skype: DKroot > > -- > Before posting, please read http://watir.com/support. In short: search before > you ask, be nice. > > watir-general@googlegroups.com > http://groups.google.com/group/watir-general > watir-general+unsubscr...@googlegroups.com Regards, Rahul Sharma -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com