【问题标题】:selenium.common.exceptions.WebDriverException: Message: chrome not reachable error while using find_element_by_id Selenium with ChromeDriverselenium.common.exceptions.WebDriverException:消息:使用 find_element_by_id Selenium 和 ChromeDriver 时出现 chrome 无法访问错误
【发布时间】:2018-08-18 17:38:16
【问题描述】:

这里是html代码:

< input class="form-control input-lg input auto-complete" id="ymMsgInput" type="text" placeholder="Type your message ..." autocomplete="off" >

代码:

i = s.find_element_by_id("ymMsgInput");

Python - Selenium Chrome 网络驱动程序错误:

Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    i = s.find_element_by_id("ymMsgInput");
  File "C:\Users\vishn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 351, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "C:\Users\vishn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 955, in find_element
    'value': value})['value']
  File "C:\Users\vishn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Users\vishn\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
  (Session info: chrome=65.0.3325.146)
  (Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 10.0.16299 x86_64)

【问题讨论】:

    标签: python selenium selenium-webdriver chrome-web-driver


    【解决方案1】:

    错误说明了一切:

        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.WebDriverException: Message: chrome not reachable
    

    如果用户使用的二进制文件之间存在版本兼容性,则会出现此错误,但绝对不是您的情况:

    • 使用 chromedriver=2.36
    • 使用 chrome=65.0
    • 硒版本未知

      chromedriver=2.36 的发行说明明确提到:

      Supports Chrome v65-66

    但是,自从最新的 Chromedriver 2.36 发布以来,Selenium 用户一直面临着它的问题。这是其中一个主题:

    根本原因与提交有关:

    • Remove --disable-infobars

      因此,有几个可能的解决方案是:

    • 使用 ChromeOptions 类来最大化浏览器。

    • 删除选项 disable-infobars
    • 一个例子:

      from selenium import webdriver
      from selenium.webdriver.chrome.options import Options
      
      options = Options()
      options.add_argument("start-maximized")
      driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\path\to\chromedriver.exe')
      driver.get('https://www.google.co.in')
      print("Page Title is : %s" %driver.title)
      

    如果您的问题仍然存在,请考虑以下事项:

    • Selenium Python 客户端升级到当前级别Version 3.10.0
    • ChromeDriver升级到稳定ChromeDriver v2.35级别。
    • Chrome 版本保持在 Chrome v64.x 级别。 (as per ChromeDriver v2.35 release notes)
    • 清理你的项目工作区通过你的IDE重建你的项目只需要依赖。
    • 使用CCleaner 工具在执行测试套件之前和之后清除所有操作系统琐事。
    • 如果您的基础 Chrome 版本太旧,请通过Revo Uninstaller 将其卸载并安装最新的 GA 和已发布版本的 Chrome。
    • 执行您的Test

    【讨论】:

      【解决方案2】:

      您的例外与查找元素无关。 Selenium 无法联系 Chrome。你可以做几件事。

      1. 根据您的 selenium 版本降级/升级您的 chromedriver。

      2. 将 --no-sandbox 传递给 chrome 选项。

        chrome_options.add_argument('--no-sandbox')
        chrome = webdriver.Chrome('/usr/local/bin/chromedriver', chrome_options=chrome_options)
        

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-11-01
        • 1970-01-01
        • 2020-04-16
        • 1970-01-01
        • 1970-01-01
        • 2019-02-27
        • 2019-06-16
        相关资源
        最近更新 更多