由于“此浏览器或应用可能不安全",因此无法使用Selenium自动化登录google. [英] Unable to sign into google with selenium automation because of "This browser or app may not be secure."

查看:5132
本文介绍了由于“此浏览器或应用可能不安全",因此无法使用Selenium自动化登录google.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用硒登录google,但我不断收到错误消息此浏览器或应用可能不安全."

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

我用来登录的功能是:

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);
}

与以下问题相同 https://stackoverflow.com/questions/59433453/无法登录到selenium-chrome-driver中的Google帐户 https://stackoverflow.com/questions/59276975/无法在此浏览器或应用中签名您可能不安全的python-selenium-chrome

It is the same problem as https://stackoverflow.com/questions/59433453/unable-to-log-into-google-account-in-selenium-chrome-driver and https://stackoverflow.com/questions/59276975/couldnt-sign-you-in-this-browser-or-app-may-be-insecure-python-selenium-chrome

我尝试同时使用chrome和firefox Web驱动程序,但均无法正常工作. 我也试过做.excludeSwitches(['enable-automation']),但也无济于事.

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?

我也查看了User-Agent来查看是否是问题所在,但发现它与我的常规Chrome完全相同.

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.

所有这些都没有奏效,这使我陷于困境.我见过一些解决方案,说要使用您在普通的chrome安装中已经创建的用户个人资料,但这不适用于我的用例.

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.

看来最近这引起了很多关注.我找到了一个解决方案,使我可以继续使用自动化客户端,而不会遇到太多问题.切换到Puppeteer. 查看以下软件包:

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:

    "puppeteer",
    "puppeteer-extra",
    "puppeteer-extra-plugin-stealth"

推荐答案

此错误消息...

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.

...表示 WebDriver 无法验证浏览上下文,即 Browser 会话.

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

此错误背后可能有多种原因,如下所示:

There can be diverse reason behind this error as follows:

  • @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.
  • Another pottential reason can be usage of Less secure apps. If an app or site doesn’t meet google-chrome's security standards, Google may block anyone who’s trying to sign in to your account from it. Less secure apps can make it easier for hackers to get in to your account, so blocking sign-ins from these apps helps keep your account safe.

在这些情况下,相应的解决方案是:

In these cases the respective solution would be to:

  • Disable Two Factor Authentification for this Google account and execute your @Test.
  • Allow less secure apps

您可以在登录中找到详细的讨论gmail帐户失败(硒自动化)


tl;博士

一些相关的事件文档:


tl; dr

A couple of relevent documentation:

这篇关于由于“此浏览器或应用可能不安全",因此无法使用Selenium自动化登录google.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆