硒谷歌登录块 [英] Selenium Google Login Block
问题描述
我对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 for this. I solved this issue by using one of my old verified account. That can be a quick solution for you also.
推荐答案
此错误消息...
...表示 WebDriver 实例无法认证浏览上下文,即 Browser 会话.
...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:
-
在文章>"安全"尝试在桌面应用上使用Google登录时出现错误 @Raphael Schaad提到,如果用户可以使用其他Google帐户登录到同一应用,那么问题一定出在特定帐户上.在大多数情况下,可能的原因是,此特定用户帐户配置了双重身份验证.
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:
- 为此Google帐户禁用双重身份验证,并执行您的 @Test .
- 允许安全性较低的应用
- Disable Two Factor Authentification for this Google account and execute your @Test.
- Allow less secure apps
深潜
但是,为了帮助保护您的帐户,网络浏览器可能不允许您从某些浏览器登录. 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 的浏览器:
Chrome
Safari
Firefox
Opera
Internet Explorer
Edge
在 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 /不安全/不受支持的扩展并且您可能需要按以下步骤关闭:
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
Finally, some old browser versions might not be supported, so ensure that:
- JDK 已升级到当前级别 JDK 8u241 .
- 硒已升级到当前级别版本3.141.59 .
- ChromeDriver 已更新为当前的 ChromeDriver v80. 0 级.
- Chrome 已更新为当前的 Chrome版本80.0 级别. (根据 ChromeDriver v80.0发行说明)
- 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)
这篇关于硒谷歌登录块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!