Unable to sign into google with selenium automation because of "This browser or app may not be secure."

I am trying to login to google with selenium and I keep getting the error that "This browser or app may not be secure."

The function I use to log in is:

async function loginToChrome(driver, username, password) {
  await driver.get("");
  await driver.sleep(1000);
  let email_phone = await driver.findElement(
  await email_phone.sendKeys(username);
  await driver.findElement("identifierNext")).click();
  await driver.sleep(1000);

  let passEl = await driver.findElement(By.xpath("//input[@name='password']"));
  await passEl.sendKeys(password);
  await driver.findElement("passwordNext")).click();
  await driver.sleep(1000);

It is the same problem as and

I have tried using both the chrome and firefox web drivers and both don't work. I have also tried doing .excludeSwitches(['enable-automation']) which also didn't help.

This made me think that maybe the sign-in page could detect that I was running in an automated environment. I tried this solution that would hide that the app is running in a web driver: Can a website detect when you are using selenium with chromedriver?

I have also looked into the User-Agent to see if that was the problem but what I have found is that it is identical to my regular chrome one.

All of this has not worked which makes leaves me stuck. I have seen solutions that say to use an already created user profile from your normal installation of chrome, but this wouldn't work for my use case.

Has anyone found the solution to this? I have been searching for hours and have come up empty-handed.

EDIT: It seems like this has been getting a lot of attention recently. I found a solution that allowed me to continue to use an automated client without having too many problems. Switching to Puppeteer. Look into these packages:


EDIT 2: I have seen this get a lot of attention recently. I found the code that I ended up using to login. I used puppeteer instead of selenium to do this

async function login(
  page: Page,
  username: string,
  password: string,
  backup: string
) {
  await page.goto("");

  await page.waitForNavigation();

  await page.waitForSelector('input[type="email"]');

  await page.waitForNavigation();

  //TODO : change to your email
  await page.type('input[type="email"]', username);
  await page.waitForSelector("#identifierNext");

  await page.waitFor(1000);

  await page.waitForSelector('input[type="password"]');
  await page.waitFor(500);
  //TODO : change to your password
  await page.type('input[type="password"]', password);

  await page.waitForSelector("#passwordNext");
  await page.waitForNavigation();


  • The followings work me as well: 1. try to login stackoverflow with your google account 2. once login, go to the email

    here is solution

         WebDriver driver;
        System.setProperty("", "chromeDriver/chromedriver.exe");
        driver = new ChromeDriver();
         GeneralClass te =  new GeneralClass ();
                + ""
                + ".com&approval_state=!ChRoYWVvLUlNMk5hSXJWUGlaSVl2WBIfc3lSa0lueENpb29lSU5vbEVpbVNxcUZGaGNkSEJoYw%E2%88%99AJDr988AAAAAXlBKc7PzEomxSzgNqd4wLptVlf0Ny3Qx&oauthgdpr=1&xsrfsig=ChkAeAh8T8JNDxCf2Zah5fb_rQ55OMiF8KmMEg5hcHByb3ZhbF9zdGF0ZRILZGVzdGluYXRpb24SBXNvYWN1Eg9vYXV0aHJpc2t5c2NvcGU&flowName=GeneralOAuthFlow");
         te.waitingForElementSendingKey(driver,"identifierId"), "[email protected]");
         te.waitingForElementSendingKey(driver,"password"), "PASSSWORD");