【问题标题】:Python script crashes after opening selenium Chrome web driver in a specific profile在特定配置文件中打开 selenium Chrome 网络驱动程序后 Python 脚本崩溃
【发布时间】:2020-08-11 05:12:24
【问题描述】:

我正在使用 python 在特定配置文件中打开 chrome web 驱动程序,如下所示:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.add_argument(r'user-data-dir=C:\Users\retro\AppData\Local\Google\Chrome\User Data')
options.add_argument('--profile-directory=Profile 1')
driver = webdriver.Chrome(r'chromedriver.exe', options=options)

尝试运行它的脚本显示以下错误堆栈。但是,该窗口在我想要的配置文件中的 Chrome 中打开,并且在那里保持打开状态!

完整的错误堆栈:

WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 10.0.20180 x86_64)

编辑 1:

我还添加了以下两个选项,一些解决方案建议但仍然没有用:

options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

并且我已经确定我使用的是正确的 webdriver 版本,即 84,它与我的 chrome 版本相匹配。当我尝试使用最新版本时,它会引发一个错误,即驱动程序版本仅适用于 chrome 版本 85。

编辑 2:

我也添加了端口号:

options.add_argument("--remote-debugging-port=9222")

添加虽然结果相同,但它会更改错误堆栈如下:

WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (chrome not reachable)
  (The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 10.0.20180 x86_64)

【问题讨论】:

    标签: python selenium google-chrome selenium-webdriver selenium-chromedriver


    【解决方案1】:

    此错误消息...

    WebDriverException: Message: unknown error: Chrome failed to start: crashed
      (unknown error: DevToolsActivePort file doesn't exist)
      (The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
      (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 10.0.20180 x86_64)
    

    ...暗示 ChromeDriver 无法启动/生成新的浏览上下文,即 Chrome 浏览器 会话。

    您的主要问题是您使用的二进制文件版本之间的不兼容性,如下所示:

    • 您正在使用 chromedriver=2.42
    • chromedriver=2.42 的发行说明明确提及以下内容:

    支持 Chrome v68-70

    • 可能您使用的是最新的 chrome=84.0
    • ChromeDriver v84.0 的发行说明明确提及以下内容:

    支持Chrome 84版

    所以 ChromeDriver v2.42Chrome 浏览器 v84.0

    之间存在明显的不匹配

    解决方案

    确保:

    • Selenium 升级到当前级别 Version 3.141.59
    • ChromeDriver 已更新到当前的ChromeDriver v84.0 级别。
    • Chrome 已更新到当前的 Chrome 版本 84.0 级别。 (根据ChromeDriver v84.0 release notes
    • 如果您的基本 Web 客户端 版本太旧,请卸载它并安装最新的 GA 和发布版本的 Web 客户端
    • 清理你的项目工作区通过你的IDE重建你的项目只需要依赖。
    • 进行系统重启
    • 非root用户身份执行@Test
    • 始终在 tearDown(){} 方法中调用 driver.quit() 以优雅地关闭和销毁 WebDriverWeb Client 实例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多