【发布时间】: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