登录 gmail 帐户失败(硒自动化) [英] Sign in to gmail account fails (selenium automation)

查看:21
本文介绍了登录 gmail 帐户失败(硒自动化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Selenium 服务,第一步必须登录到我的 gmail 帐户.这个功能在几周前可以工作,但突然登录开始失败,我在浏览器中看到这个错误,在 selenium 的 Chrome 和 Firefox 驱动程序中都试过 -

I have a Selenium service that has to login to my gmail account as the first step. This functionality was working couple of weeks ago, but suddenly the login starts to fails and i am seeing this Error in browser, tried both in Chrome and Firefox drivers in selenium -

在 selenium 服务插入电子邮件、密码并单击登录按钮后出现此错误.在此处的 Google 支持论坛中也报告了类似的错误 - https://support.google.com/accounts/thread/10916318?hl=en,他们说谷歌似乎在他们的登录流程中引入了自动化工具检测!"但是这个线程没有解决方案.

This Error comes after the selenium service inserts the email,password and clicks on the sign in button. A similar error was also reported in Google support Forum here- https://support.google.com/accounts/thread/10916318?hl=en, They said that "Google seems to have introduced automation tools detection on their login flow!" but there is no solution in this thread.

其他一些可能有用的细节-

Some Other Details which might be useful-

  • 我无法在浏览器中手动登录 Google 帐户
    由 Selenium 打开.
  • 但我可以在 Google 中手动登录这些帐户Chrome 应用程序.

如果您需要查看代码,请告诉我,我将在此处发布.提前致谢!

Let me know if you need to take a look at the code, i will post it here. Thanks in Advance!

编辑添加示例代码以供参考.

Edit Adding Sample code to refer.

public void loginGoogleAccount(String emailId, String password) throws Exception {
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--profile-directory=Default");
    options.addArguments("--whitelisted-ips");
    options.addArguments("--start-maximized");
    options.addArguments("--disable-extensions");
    options.addArguments("--disable-plugins-discovery");
    WebDriver webDriver = new ChromeDriver(options);
    webDriver.navigate().to("https://accounts.google.com");
    Thread.sleep(3000);
    try {
        WebElement email = webDriver.findElement(By.xpath("//input[@type='email']"));
        email.sendKeys(emailId);
        Thread.sleep(1000);

        WebElement emailNext = webDriver.findElement(By.id("identifierNext"));
        emailNext.click();
        Thread.sleep(1000);

        WebDriverWait wait = new WebDriverWait(webDriver, 60);
        wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("identifierNext")));

        Thread.sleep(3000);
        WebElement passwordElement = webDriver.findElement(By.xpath("//input[@type='password']"));
        passwordElement.sendKeys(password);

        Thread.sleep(1000);
        WebElement passwordNext = webDriver.findElement(By.id("passwordNext"));
        passwordNext.click();

    } catch (Exception e) {
        LOGGER.info(String.format("No email/password field available or it is already logged in: [%s]: ",
                e.getMessage()));
    }
}

推荐答案

切换允许不太安全的应用程序访问"
您的帐户中有一个设置,您可以切换它可能对此有所帮助.它是允许不太安全的应用程序访问".如果您已经登录到要修改的 gmail 帐户,您应该可以访问下面的链接来切换该设置.

Toggle "Allow Less Secure App Access"
There is a setting on your account that you can toggle that may help with this. It is the "Allow Less Secure App Access". You should be able to visit the link below to toggle that setting if you are already logged into the gmail account you want to modify.

更改 Google 帐户设置的链接:https://myaccount.google.com/lesssecureapps

Link to change setting on google account: https://myaccount.google.com/lesssecureapps

更多信息(来源):https://support.google.com/accounts/answer/6010255

这篇关于登录 gmail 帐户失败(硒自动化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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