in reply to Can't get past Google login with WWW::Mechanize::Chrome
After some trying, I think there is at least a smallish bug with WWW::Mechanize::Chrome that doesn't let it recognized when pushing a button doesn't result in navigation (fixed on Github).
Other than that, it seems that simply filling the Password field doesn't set the value in the way that the Google login application expects it. I've worked around this in my working example code by sending the keystrokes to the password entry manually. Most likely this "send keystrokes" method will find its way into WWW::Mechanize::Chrome soonish.
#!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 ER +ROR 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 fie +ld $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 => 'cha +r', text => $key)->get; }; $mech->sleep(1); #$logger->info("Clicking Sign in button"); #$mech->click({ selector => '#passwordNext', single => 1 }); # for hea +dful $mech->click({ selector => '#signIn', single => 1 }); # for headless warn $mech->title; undef $mech; sleep 5;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can't get past Google login with WWW::Mechanize::Chrome
by lpowers (Acolyte) on Aug 25, 2018 at 01:38 UTC |