xgamma has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I'm having a bit of trouble with my first foray into this module. Here's my sample code:

use Win32::IE::Mechanize; my $ie = Win32::IE::Mechanize->new( visible => 1 ); my $url = "https://somesecuresite"; my $formName = "loginForm"; $ie->get( $url ); $ie->form_name( $formName ); $ie->set_fields( userName => 'username', password => 'password' );

As expected, the browser opens up and goes to the specified URL. However, the text doesn't get entered into the fields. I get this error: Can't call method "find_input" on an undefined value at C:/Perl/site/lib/Win32/IE/Mechanize.pm line

I'm also not sure how to click the login button afterwards because it's an image.

Replies are listed 'Best First'.
Re: Win32::IE::Mechanize trouble
by pc88mxer (Vicar) on Jun 19, 2008 at 19:14 UTC
    Check if $ie->form_name(...) is returning undef. That indicates that the form wasn't found and would explain the error message you are getting.

    As for the button, what kind of form control is it, a <button> or <input type=submit ...> or an anchor that executes javascript?

    I would see if the $ie->click(...) or $ie->submit(...) will work for you.

      How would I go about finding out if it's undefined?

      It's a button

      <span class="button"><a href="javascript:clickedButton('submitLogin'); +"> <img xmlns="http://www.w3.org/1999/xhtml" title="" src="en/images/lan +guage_sensitive_images/pagegraphics/buttons/image/go.gif" class="" al +t=""/> </a></span>
        No, it's an anchor that executes javascript. You need to follow the link.
        The button is an anchor which calls the JS routine clickedButton(). You'll just have to look at the JS code to see what really is going on.
Re: Win32::IE::Mechanize trouble
by ikegami (Patriarch) on Jun 19, 2008 at 19:12 UTC

    Like the message says the field userName or the field password can't be found in the form you specified, if it even found such the form you specified. What are you expecting from us?

      That was my initial thought too, but I revised the source code for the page, and here is the area where it's specified.

      <td> <input type="text" name="userName" maxlength="24" size="12" +tabindex="1" value="" onkeypress="return enterToSubmit()" class="text +field0"> </td> <td> <span class="label">new visitor: <a href="javascript:goToUrl +('goToRegistration');">register</a></span> </td> </tr> <tr> <td> <span class="label">password:</span> </td> <td> <input type="password" name="password" maxlength="24" size=" +12" tabindex="2" value="" onkeypress="return enterToSubmit()" class=" +textfield0"> </td> <td>

      And so I'm not so sure that that's the issue.

        I don't know if the ids are case sensitive, but password isn't properly cased

        You haven't shown that the form is properly selected. pc88mxer has some advice on that.

        And it wouldn't hurt to find out which input it can't find.