Shun Takeda
Shun Takeda

Reputation: 216

Mechanize Post with 2 submits

I'm pretty new to Mechanize... and I'm still learning.

I was wondering if someone could help me out with this problem I have.

I'm messing around with the web developer kit via Firefox to figure out the forms, but I'm having some trouble doing this.

The website I am trying to post submit has 2 submit buttons. The entire page is mostly javascript and jquery code so to go around that mess I figured out that I need to post info directly to the page like so...

 @page = Mechanize.new{|agent| agent.user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0a2) Gecko/20111101 Firefox/9.0a2'} 
 @page.post("http://www.somepage.do",'name1' => '1','name2' => '2', 'name3' => '3')

There are multiple buttons on the page as displayed as image files with no direct link available:

   <input id="btn1" type="image" title="Search" src="images/img/common/btn.gif" name="button1">
   <input id="btn2" type="image" title="Search" src="images/img/common/btn.gif" name="button2">

When I pull the form from the site... I see...

ID='btn1', name = 'btn1', type ='image', 'value' = ''

I know if I had the direct link... I should post something like...

 @page.post("http://www.somepage.do/button2.html", 'name1' => '1','name2' => '2', 'name3' => '3')

But since most of the page is done is javascript it is difficult to look for stuff.

Any help or suggestions will be welcome. Thanks in advance.

EDIT:

Ok... I just found out a few things... When I

@page.post("http://www.somepage.do",'name1' => '1','name2' => '2', 'name3' => '3')

For some odd reason 'name1' and 'name2' doesn't get populated into the form.
I grabbed these names directly from the website.

Upvotes: 1

Views: 168

Answers (1)

Kibet Yegon
Kibet Yegon

Reputation: 2833

Since you mentioned that you are using Firefox, install the HTTPFox add-on and use it to analyze what the submit button posts to the web server when you click on a submit button. That way, you can easily mimic what the Javascript is doing by populating the form with values or even add more input fields to the form (if javascript is adding any extra fields before submit). I've used this technique succesfully many times on websites that do alot of javascript form processing on submit.

Upvotes: 1

Related Questions