use strict; use warnings; use WWW::Mechanize::PhantomJS; my $mech = WWW::Mechanize::PhantomJS->new(); $mech->get('https://profile.ccli.com/account/signin?appContext=OLR&returnUrl=https%3A%2F%2Freporting.ccli.com%2F'); $mech->field( EmailAddress => 'me@test.com' ); $mech->field( Password => 'mypw' ); my $ori_uri = $mech->uri; print "clicking from '$ori_uri' ... \n"; my $x = $mech->click_button( id => 'sign-in' ); my $maxtime = 50; # do this for a max of 50 seconds my $success; while($maxtime-->0){ print "checking if uri has changed from original : '".$mech->uri."' ...\n"; if( $mech->uri ne $ori_uri ){ $success = 1; last } # similarly check for the contents of the error textbox otherwise sleep(1); } die "something went wrong and never left the page..." unless $success; print "finally left and now in this uri : ".$mech->uri."\n"; $mech->render_content( format => 'png', filename => 'ccli_login.png' ); print "done!\n";