【问题标题】:How to fix gmail security error in Chrome by selenium python 2.7?如何通过 selenium python 2.7 修复 Chrome 中的 gmail 安全错误?
【发布时间】:2018-04-01 22:24:05
【问题描述】:

我想在 Chrome 中使用 selenium python 2.7 打开 gmail 帐户。我能够成功登录到 gmail 帐户。但是,有时,我可以得到 Its you verify 按摩,然后它会询问电子邮件 ID 或电话号码,以验证使用该帐户的问题。那么,我们可以使用if-else 条件或其他东西吗?如何在登录到 gmail 帐户时使用if-else 条件进行您验证步骤。 请给我建议任何其他方法来解决我的问题。谢谢 我无法使用此查询附加屏幕截图(stackoverflow.com 不允许我附加任何图像)。

请提供 if else 条件来解决此问题。谢谢

【问题讨论】:

  • 使用try/except 捕获异常,并在except 块中编写处理验证屏幕过程的代码

标签: python-2.7 google-chrome email selenium if-statement


【解决方案1】:

您可以检查 not 上是否存在“Its you verify”元素,然后可以继续执行所需的步骤。

List <Webelement> verify = driver.findElemnts(By.xpath("//*[contains(text(),'Its you verify')]"));

if(verify.count>0)
{
  //Do verify action
}

上面提到的xpath只是一个例子,你可以在使用前进行验证。

【讨论】:

    【解决方案2】:

    跳出框框思考...为什么还要在浏览器中使用 selenium 来驱动 gmail?如果您不测试 gmail 的浏览器 GUI 本身,那么我建议您使用 Gmail API 来获取您的消息。

    【讨论】:

      【解决方案3】:

      我有另一种解决方案,可以毫不费力地工作。 将Seleniumwireundetected browser v2 一起使用

      注意:将 chromedriver 放在你的系统路径中。

      from seleniumwire.undetected_chromedriver.v2 import Chrome, ChromeOptions
      import time
      
      options = {}
      chrome_options = ChromeOptions()
      chrome_options.add_argument('--user-data-dir=hash')
      chrome_options.add_argument("--disable-gpu")
      chrome_options.add_argument("--incognito")
      chrome_options.add_argument("--disable-dev-shm-usage")
      # chrome_options.add_argument("--headless")
      browser = Chrome(seleniumwire_options=options, options=chrome_options)
      
      browser.get('https://gmail.com')
      browser.find_element_by_xpath('//*[@id="identifierId"]').send_keys('your-email')
      browser.find_element_by_xpath('//*[@id="identifierNext"]/div/button').click()
      time.sleep(5)
      browser.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys('you-password')
      browser.find_element_by_xpath('//*[@id="passwordNext"]/div/button').click()
      

      除此之外,selenium 线还有许多很棒的功能,请查看 Github repository

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-05-27
        • 2020-01-17
        • 1970-01-01
        • 1970-01-01
        • 2015-03-22
        • 1970-01-01
        • 2015-05-15
        相关资源
        最近更新 更多