#!perl use strict; use warnings; use Log::Log4perl ':easy'; use WWW::Mechanize::Chrome; use File::Temp 'tempdir'; Log::Log4perl->easy_init($TRACE); # Set priority of root logger to ERROR my $mech = WWW::Mechanize::Chrome->new( headless => 1, data_directory => tempdir(CLEANUP => 1), #profile => tempdir(CLEANUP => 1), ); my $url = 'https://keep.google.com'; my( $user, $pass) = @ARGV; my $response = $mech->get($url); $mech->sleep(3); # Click in Login Email form field $mech->form_number(1); #warn $mech->current_form->get_attribute('innerHTML'); my $username = $mech->xpath('//input[@type="email"]', single => 1 ); $username->set_attribute('value', "$user"); # For headless, it's "next" $mech->click({ xpath => '//*[@id="next"]' }); #$mech->click({ xpath => '//*[@id="identifierNext"]', synchronize => 0 }); #$mech->sleep(1); #$mech->sleep(60); #$mech->click_button( name => 'signIn' ); # Give time for password page to load $mech->sleep(5); #my @f = $mech->xpath('//FORM'); #for my $form ( @f ) { # print $form->get_attribute('innerHTML'), "\n"; #print "---\n"; #}; # Click in Password field my $password_field = $mech->xpath('//input[@type="password"]', single => 1 ); #my $password_html = $mech->selector('#password', single => 1 ); #$mech->click( $password_html ); # html "field" to enable the real field $mech->click( $password_field ); # when headless #$password_field->set_attribute('value', "$pass"); #$password_field->set_attribute('data-initial-value', "$pass"); #$password_field = $mech->xpath('//input[@type="password"]', single => 1 ); for my $key (split //, $pass) { # "type" in the password $mech->driver->send_message('Input.dispatchKeyEvent', type => 'char', text => $key)->get; }; $mech->sleep(1); #$logger->info("Clicking Sign in button"); #$mech->click({ selector => '#passwordNext', single => 1 }); # for headful $mech->click({ selector => '#signIn', single => 1 }); # for headless warn $mech->title; undef $mech; sleep 5;