Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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" action="https://www.pharmgkb.org/cas/login? service=http%3A%2F%2Fpreview.pharmgkb.org%2F views%2Findex.jsp%3Fid%3Dhome.welcome" /> <table border="0" cellpadding="4" cellspacing="0"> <tr> <th align="right">Username:</th> <td align="left"><input type="text" name="username" tabindex="1" /></td> <td rowspan="2"> <a href="/mypharmgkb/profile/accountReminder.action"> Forgot your User ID and/or password?</a></td> </tr><tr> <th align="right">Password:</th> <td align="left"><input type="password" name="password" tabindex="2" /></td> </tr><tr> <td align="right">&nbsp;</td> <td align="left" colspan="3"><input type="submit" value="Sign In" tabindex="3" /> <input type="reset" tabindex="4" /></td> <td>&nbsp;</td> </tr> </table> </form>

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):
use strict; use warnings; use WWW::Mechanize; use HTTP::Cookies; my $mech_obj = WWW::Mechanize->new(); $mech_obj->get( $signin_url ); if( not $mech_obj->success() ) { print "Could not retrieve signin page:\n"; print $mech_obj->content(); die; } $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!


In reply to Clicking nameless buttons with WWW::Mechanize by bobf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-19 04:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found