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

≡放荡痞女 提交于 2020-01-15 03:23:06

问题


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("https://accounts.google.com/signin");
  await driver.sleep(1000);
  let email_phone = await driver.findElement(
    By.xpath("//input[@id='identifierId']")
  );
  await email_phone.sendKeys(username);
  await driver.findElement(By.id("identifierNext")).click();
  await driver.sleep(1000);

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

It is the same problem as Unable to log into google account in selenium chrome driver and couldn't sign you in this browser or app may be insecure (python selenium chrome 78)

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.


回答1:


This error message...

This browser or app may not be secure.
Try using a different browser. If you’re already using a supported browser, you can refresh your screen and try again to sign in.

...implies that the WebDriver was unable to authenticate the Browsing Context i.e. Browser session.


@Raphael Schaad in the article "This browser or app may not be secure" error when trying to sign in with Google on desktop apps mentioned that, if an user can log into the same app just fine with other Google accounts, then the problem must lie with the particular account. The possible reason, it is the only account where user is using Two Factor Authentification.


tl; dr

Sign in with a supported browser



来源:https://stackoverflow.com/questions/59514049/unable-to-sign-into-google-with-selenium-automation-because-of-this-browser-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!