use strict; use warnings; use Selenium::Remote::Driver; use LWP::UserAgent; use Data::Dumper; my $wait_period = $ENV{ SP_WAIT_PERIOD } ? $ENV{ SP_WAIT_PERIOD } : 5; my $ua = LWP::UserAgent->new( "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0" ); $ua->default_header( 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'); $ua->default_header( 'Accept-Encoding' => 'gzip, deflate, br' ); $ua->default_header( 'Accept-Language' => 'de,en-US;q=0.7,en;q=0.3' ); $ua->default_header( 'Cache-Control' => 'no-cache' ); $ua->default_header( 'Connection' => 'keep-alive' ); $ua->default_header( 'DNT' => 1 ); $ua->default_header( 'Host' => 'myibd.investors.com' ); $ua->default_header( 'Pragma' => 'no-cache' ); $ua->default_header( 'Referer' => 'https://www.investors.com/' ); $ua->default_header( 'Upgrade-Insecure-Requests' => 1 ); #print STDERR "REQUEST HEADER FIELDS:\n"; #print STDERR join( "\n", $ua->default_headers->header_field_names() ); my $selen=Selenium::Remote::Driver->new( browser_name => 'firefox', ua => $ua ); $selen->debug_on; print STDERR "INFO: Created new Web Driver instance.\n"; my $url="https://myibd.investors.com/secure/signin.aspx?eurl=https://www.investors.com/"; $selen->set_timeout( 'page load', 60000); $selen->set_timeout( 'implicit', 100); $selen->get( $url ); sleep( $wait_period ); my $fh; open( $fh, ">", "first_page.htm"); print $fh $selen->get_page_source(); close( $fh ); my $elem; #eval{ $elem = $selen->find_element( "(//button[\@id='gdpr-accept-button'])" ); }; eval{ $elem = $selen->find_element( "(//a[\@id='signin-link'])" ); }; if ( $@ ) { die( "ERROR: Could not locate element using xpath " . "//a[\@id='signin-link']." ); } my $trials = 0; my $retcode; while ( $trials < 10 ) { eval { $retcode = $elem->click() }; if ( $@ ) { warn( "ERROR: Could not navigate to login page. $@" ); } if ( $retcode ) { print STDERR "Click successful, waiting for page to load ...\n"; sleep( 20 ); last; } $trials++; print STDERR "\$retcode: $retcode\n"; sleep( 1 ); } open( $fh, ">", "second_page.htm"); print $fh $selen->get_page_source(); close( $fh );