login into gmail fails for unknown reason

Tags: , ,



I am trying to login into my gmail with puppeteer to lower the risk of recaptcha

here is my code

    await page.goto('https://accounts.google.com/AccountChooser?service=mail&continue=https://mail.google.com/mail/', {timeout: 60000})
        .catch(function (error) {
            throw new Error('TimeoutBrows');
        });

    await page.waitForSelector('#identifierId' , { visible: true });
    await page.type('#identifierId' , 'myemail');
    await Promise.all([
        page.click('#identifierNext') ,
        page.waitForSelector('.whsOnd' , { visible: true })
    ])
    await page.type('#password .whsOnd' ,  "mypassword");
    await page.click('#passwordNext');
    await  page.waitFor(5000);

but i always end up with this message

enter image description here

I even tried to just open the login window with puppeteer and fill the login form manually myself, but even that failed.

Am I missing something ?

When I look into console there is a failed ajax call just after login.

Request URL: https://accounts.google.com/_/signin/challenge?hl=en&TL=APDPHBCG5lPol53JDSKUY2mO1RzSwOE3ZgC39xH0VCaq_WHrJXHS6LHyTJklSkxd&_reqid=464883&rt=j
Request Method: POST
Status Code: 401 
Remote Address: 216.58.213.13:443
Referrer Policy: no-referrer-when-downgrade


)]}'

[[["er",null,null,null,null,401,null,null,null,16]
,["e",2,null,null,81]
]]

Answer

I’ve inspected your code and it seems to be correct despite of some selectors. Also, I had to add a couple of timeouts in order to make it work. However, I failed to reproduce your issue so I’ll just post the code that worked for me.

const puppeteer = require('puppeteer');

(async () => {

    const browser = await puppeteer.launch({headless: false});
    const page = await browser.newPage();

    await page.goto('https://accounts.google.com/AccountChooser?service=mail&continue=https://mail.google.com/mail/', {timeout: 60000})
        .catch(function (error) {
            throw new Error('TimeoutBrows');
        });

    await page.screenshot({path: './1.png'});
    ...

})();

Please, note that I run browser in normal, not headless mode. If you take a look at screenshot at this position, you will see that it is correct Google login form Google login form after the first step

The rest of the code is responsible for entering password

const puppeteer = require('puppeteer');

(async () => {

    ...
    await page.waitForSelector('#identifierId', {visible: true});
    await page.type('#identifierId', 'my@email');
    await Promise.all([
        page.click('#identifierNext'),
        page.waitForSelector('.whsOnd', {visible: true})
    ]);

    await page.waitForSelector('input[name=password]', {visible: true});
    await page.type('input[name=password]', "my.password");

    await page.waitForSelector('#passwordNext', {visible: true});
    await page.waitFor(1000);
    await page.click('#passwordNext');
    await page.waitFor(5000);

})();

Please also note few differences from your code – the selector for password field is different. I had to add await page.waitForSelector('#passwordNext', {visible: true}); and a small timeout after that so the button could be clicked successfully.

I’ve tested all the code above and it worked successfully. Please, let me know if you still need some help or facing troubles with my example.



Source: stackoverflow