登录Gmail帐户失败(Selenium Automation) [英] Sign in to gmail account fails (selenium automation)

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

问题描述

我有一个Selenium服务,第一步必须登录到我的Gmail帐户.几个星期前,该功能就已经起作用了,但突然登录开始失败,并且我在浏览器中看到此错误,并在硒中的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 -

此错误是在硒服务插入电子邮件,密码并单击登录"按钮之后发生的.在Google支持论坛上也报告了类似的错误- https://support.google .com/accounts/thread/10916318?hl = zh_CN ,他们说:"Google似乎已在其登录流程中引入了自动化工具检测功能!"但是此线程中没有解决方案.

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.

一些其他有用的细节-

  • 我无法在浏览器中手动登录Google帐户
    由Selenium打开.
  • 但是我可以手动登录Google中的这些帐户 Chrome应用程序.
  • I am not able to login manually to Google accounts in the browsers
    opened by Selenium.
  • But I am able to login manually to these accounts in the Google Chrome application.

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

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

Further information(source): https://support.google.com/accounts/answer/6010255

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

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