Selenium Google 登录块 [英] Selenium Google Login Block

查看:23
本文介绍了Selenium Google 登录块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Google 登录时遇到问题.我想登录我的帐户,但 Google 说不允许自动化驱动程序登录.

I have a problem with Google login. I want to login to my account but Google says that automation drivers are not allowed to log in.

我正在寻找解决方案.是否可以获取普通 Firefox/Chrome 的 cookie 并将其加载到 ChromeDriver/GeckoDriver 中?我认为这可能是一个解决方案.但我不确定这是否可能..

I am looking for a solution. Is it possible to get a cookie of normal Firefox/Chrome and load it into the ChromeDriver/GeckoDriver? I thought that this can be a solution. But I am not sure is it possible or not..

寻找解决方案...

另外,我想添加一个快速解决方案.我解决了这个问题使用我的一个旧的验证帐户.这可以是一个快速的解决方案你.

Also, I want to add a quick solution. I solved this issue by using one of my old verified account. That can be a quick solution for you.

推荐答案

这个错误信息...

...暗示 WebDriver 实例无法验证 Browsing ContextBrowser 会话.

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

此错误可能由于以下不同因素而发生:

This error can happen due to different factors as follows:

  • In the article "This browser or app may not be secure" error when trying to sign in with Google on desktop apps @Raphael Schaad mentioned that, if an user can log into the same app just fine with other Google accounts, then the problem must be with the particular account. In majority of the cases the possible reason is, this particular user account is configured with Two Factor Authentification.

在文章中 不太安全的应用和您的 Google 帐户 提到,如果应用或网站不符合 安全标准,Google 可能会阻止任何试图通过它登录您的帐户的人.安全性较低的应用可能会让黑客更容易进入您的帐户,因此阻止从这些应用登录有助于确保您的帐户安全.

In the article Less secure apps & your Google Account it is mentioned that, 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

您可以在 无法使用 selenium 自动化登录 Google,因为此浏览器或应用程序可能不安全."


深入研究

但是,为了帮助保护您的帐户,网络浏览器可能不允许您从某些浏览器登录.Google 可能会停止从以下浏览器登录:


Deep Dive

However, to help protect your account, Web Browsers may not let you sign in from some browsers. Google might stop sign-ins from browsers that:

  • 不支持 JavaScript 或已关闭 Javascript.
  • 添加了 AutomationExtension 或不安全或不受支持的扩展.
  • 使用自动化测试框架.
  • 嵌入到不同的应用程序中.

在这些情况下,有多种解决方案:

In these cases there are diverse solutions:

  • 使用支持JavaScript的浏览器:

Safari

火狐

歌剧

Internet Explorer

边缘

Web 浏览器中启用 JavaScript:如果您使用受支持的浏览器但仍无法登录,则可能需要启用 JavaScript.

Turn on JavaScript in Web Browsers: If you’re using a supported browser and still can’t sign in, you might need to turn on JavaScript.

如果您仍然无法登录,可能是因为您打开了 AutomationExtension/unsecure/unsupported 扩展程序您可能需要按以下方式关闭:

If you still can’t sign in, it might be because you have AutomationExtension / unsecure / unsupported extensions turned on and you may need to turn off as follows:

  public class browserAppDemo 
  {
      public static void main(String[] args) throws Exception 
      {
          System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");
          ChromeOptions options = new ChromeOptions();
          options.addArguments("start-maximized");
          options.setExperimentalOption("useAutomationExtension", false);
          options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
          WebDriver driver =  new ChromeDriver(options); 
          driver.get("https://accounts.google.com/signin")
          new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='identifierId']"))).sendKeys("gashu");
          driver.findElement(By.id("identifierNext")).click();
          new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']"))).sendKeys("gashu");
          driver.findElement(By.id("passwordNext")).click();
          System.out.println(driver.getTitle());
      }
  }

  • 您可以在以下位置找到一些相关讨论:

  • You can find a couple of relevant discussions in:

    在java中使用selenium webdriver登录Gmail

    Selenium 测试脚本通过新的 ajax 登录表单登录到 google 帐户

    最后,一些旧的浏览器版本可能不被支持,所以请确保:

    Finally, some old browser versions might not be supported, so ensure that:

    • JDK is upgraded to current levels JDK 8u241.
    • Selenium is upgraded to current levels Version 3.141.59.
    • ChromeDriver is updated to current ChromeDriver v80.0 level.
    • Chrome is updated to current Chrome Version 80.0 level. (as per ChromeDriver v80.0 release notes)

    这篇关于Selenium Google 登录块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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