【问题标题】:Selenium WebDriverException - chrome not reachableSelenium WebDriverException - 无法访问 chrome
【发布时间】:2016-12-17 04:27:50
【问题描述】:

我在 linux 服务器上有一个 chrome selenium 驱动程序,它由 cron 每小时执行一次。我遇到的错误仅在后续运行中发生,也就是说,在第一次运行期间它工作正常,但在第二次或任何其他子顺序运行期间它失败了。

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
  (Session info: chrome=54.0.2840.71)
  (Driver info: chromedriver=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 4.4.0-38-generic x86_64)

我是这样运行的:

def create_ch_driver():
  chrome_options = webdriver.ChromeOptions()
  chrome_options.add_argument("--no-sandbox")
  chrome_options.add_argument("--user-agent={}".format(config.USER_AGENT))
  return webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=chrome_options)

【问题讨论】:

    标签: python linux google-chrome selenium


    【解决方案1】:

    也许驱动程序仍在后台运行并阻止创建新的 webdriver 实例。

    在第一次执行代码后检查进程是否正在运行。

    如果是这样,请尝试使用 quit() 终止进程:

    webdriver.quit()
    

    【讨论】:

    • 我每次在我的脚本中都使用 driver.close()
    • 你检查过进程是否还在运行吗?
    • 对我有意义
    猜你喜欢
    • 2022-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-02
    • 2021-02-11
    • 1970-01-01
    相关资源
    最近更新 更多