Selenium Google Login Block

问题描述 投票:2回答:2

我对Google登录有疑问。我想登录到我的帐户,但是Google表示不允许自动化驱动程序登录。

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

寻找解决方案..

enter image description here

selenium google-chrome selenium-webdriver selenium-chromedriver geckodriver
2个回答
1
投票

此错误消息...

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9YYXI2Qi5wbmcifQ==” alt =“此浏览器或应用程序可能不安全”>

...表示WebDriver实例无法认证Browsing Context,即Browser会话。


此浏览器或应用可能不安全

此错误可能是由于以下各种因素引起的:


解决方案

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

您可以在Unable to sign into google with selenium automation because of "This browser or app may not be secure."中找到详细的讨论


深潜

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

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

解决方案

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

  • 使用支持JavaScript的浏览器:

    • Chrome
    • Safari
    • Firefox
    • Opera
    • Internet Explorer
    • Edge
  • Web浏览器]中打开JavaScript:如果使用的是受支持的浏览器,但仍然无法登录,则可能需要打开JavaScript。

  • 如果仍然无法登录,可能是因为您打开了[[AutomationExtension

  • / 不安全 / 不支持扩展名,您可能需要按以下步骤关闭:] >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()); } }
  • 您可以在以下位置找到几个相关的讨论:

  • Selenium test scripts to login into google account through new ajax login form

  • 其他注意事项
  • 最后,某些旧版本的浏览器可能不受支持,因此请确保:

    一个对我有用的解决方案:https://stackoverflow.com/a/60328992/12939291https://www.youtube.com/watch?v=HkgDRRWrZKg

    简短:使用重定向的Google帐户登录Stackoverflow

    from selenium import webdriver from time import sleep class Google: def __init__(self, username, password): self.driver = webdriver.Chrome('./chromedriver') self.driver.get('https://stackoverflow.com/users/signup?ssrc=head&returnurl=%2fusers%2fstory%2fcurrent%27') sleep(3) self.driver.find_element_by_xpath('//*[@id="openid-buttons"]/button[1]').click() self.driver.find_element_by_xpath('//input[@type="email"]').send_keys(username) self.driver.find_element_by_xpath('//*[@id="identifierNext"]').click() sleep(3) self.driver.find_element_by_xpath('//input[@type="password"]').send_keys(password) self.driver.find_element_by_xpath('//*[@id="passwordNext"]').click() sleep(2) self.driver.get('https://youtube.com') sleep(5) username = '' passwort = '' Google(username, password)


    © www.soinside.com 2019 - 2024. All rights reserved.