I finally had an occasion to try out WWW::Mechanize, so I eagerly read the docs and started coding. I am somewhat embarassed to admit that I got stuck almost immediately. I am trying to log in, but I can't figure out how to post the form once I've filled it in because the submit button is in a table and it is unnamed.
The source HTML for this form is as follows:
<form method="POST" id="loginForm"
<table border="0" cellpadding="4" cellspacing="0">
<td align="left"><input type="text" name="username"
Forgot your User ID and/or password?</a></td>
<td align="left"><input type="password" name="password"
<td align="right"> </td>
<td align="left" colspan="3"><input type="submit"
value="Sign In" tabindex="3" />
<input type="reset" tabindex="4" /></td>
This form is the second form on the page. I confirmed that I had the correct form by doing:
print Dumper( $mech_obj->current_form() );
Here is the relevant part of my code (meager, I know):
my $mech_obj = WWW::Mechanize->new();
$mech_obj->get( $signin_url );
if( not $mech_obj->success() )
print "Could not retrieve signin page:\n";
$mech_obj->form_number( 2 );
$mech_obj->set_fields( 'username' => $username,
'password' => $password );
I've tried to submit the form using the submit method, but it seems the first form on the page (a website search box) is submitted instead of the login form. I also tried using the click method, but I can't figure out what the name of the button is (using click without specifying the button name also submits the search box instead of the login form).
Since the button is in a table and doesn't appear to have a name, I thought using the optional arguments (x, y coordinates for the button) with the click method, but 1) the name of the button still appears to be required, and 2) I don't know how to determine the button coordinates on the page.
I Googled the net and Super Searched the Monastery's archives, but came up empty. Any ideas?
Thanks in advance!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] |