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

I am not sure what I am not doing correctly here. I've also tried a delay in the code and that does not work either. I get the following error: Can't call method "find_input" on an undefined value at C:/Perl/site/lib/Win32/IE/Mechanize.pm line 967. Using this code:
$ie = Win32::IE::Mechanize->new(); $ie->get( $url ); $ie->submit_form( #form_name => 'logOnForm', form_number => 2, fields => { username => '1234', password => '1234', }, button => { value => 'Log in' } );

Replies are listed 'Best First'.
Re: Win32::IE::Mechanize Issues
by roboticus (Chancellor) on May 05, 2009 at 17:25 UTC
    everlast88az:

    Debugging 101: With the error message given, I'd first suspect that you're calling Win32::IE::Mechanize incorrectly. Since you call it three times, you should determine which call is failing and/or check the related values

    perl has a nice debugging mode built into it, which you could use to set a breakpoint at line 967. Then when the program fails, you can look at the values, and examine the call stack to see where they're coming from, and why.

    However, many people don't use the debugger. Instead they would print trace messages in various locations, combined with dumping the actual values involved. Something like:

    #!/usr/bin/perl -w sub trace { print join(' ', map { defined($_) ? $_ : '#undef#' } @_), +"\n"; } my $val; trace('Before first chunk, value is', $val); $val='foobar'; trace('Before second chunk, value is', $val); $val=7.3; trace('Final value is', $val);

    Running that would show:

    roboticus@swill $ ./foo.pl Before first chunk, value is #undef# Before second chunk, value is foobar Final value is 7.3

    You can see that on the first chunk, $val is undefined.

    So, you might verify that $ie actually contains a legitimate value. If it is, then you could check whether $url is defined.

    ...roboticus
      Thanks I will try that. I forgot all about debuggers in perl.
Re: Win32::IE::Mechanize Issues
by afoken (Chancellor) on May 05, 2009 at 08:18 UTC

    Node 761833

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
    A reply falls below the community's threshold of quality. You may see it by logging in.