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

I use Win32::IE::Mechanize to try to login at https://secure.10kwizard.com/login.php
The program some times works. I can login and see what I wanted.
But some times it doesn't. It stopped at the login page and nothing happened.
when it doesn't work, it tells me
"Can't call method "find_input" on an undefined value at E:/Perl/site/lib/Win32/IE/Mechanize.pm line 967."
Could somebody help me? Thanks!
#!/usr/bin/perl use strict; use Win32::IE::Mechanize; my $username = '1234'; my $password = '1234'; my $url = "https://secure.10kwizard.com/login.php"; my $ie = Win32::IE::Mechanize->new( visible => 1 ); my $fn = "login"; #my $fn = 2; $ie->get( $url ); print $username."-".$password."-".$fn."\n"; print "first time-".$ie->uri."\n"; $ie->submit_form( form_name => $fn, fields => { email => $username, password => $password, }, ); print "second time-".$ie->uri; exit;

Replies are listed 'Best First'.
Re: Question for Win32::IE::Mechanize
by walto (Pilgrim) on Mar 15, 2008 at 08:17 UTC
    I found that it sometimes takes a while for Win32::IE::Mechanize to get a page and process the commands. It seems that $ie->success is not always relyable. What you can do is give a little more time to process your request adding sleep.
    #!/usr/bin/perl use strict; use Win32::IE::Mechanize; my $username = '1234'; my $password = '1234'; my $url = "https://secure.10kwizard.com/login.php"; my $ie = Win32::IE::Mechanize->new( visible => 1 ); my $fn = "login"; #my $fn = 2; $ie->get( $url ); sleep 1; # or more if needed print $username."-".$password."-".$fn."\n"; print "first time-".$ie->uri."\n"; $ie->submit_form( form_name => $fn, fields => { email => $username, password => $password, }, ); sleep 1; # or more if needed print "second time-".$ie->uri; exit;