【问题标题】:Selenium webdriver error Chrome failed to start [duplicate]Selenium webdriver错误Chrome无法启动[重复]
【发布时间】:2019-06-18 02:01:15
【问题描述】:

我正在尝试通过 Selenium 打开 Chrome 网络驱动程序,但在初始化时出现错误。我收到的错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "F:\WinPython\python-3.6.7.amd64\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "F:\WinPython\python-3.6.7.amd64\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "F:\WinPython\python-3.6.7.amd64\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "F:\WinPython\python-3.6.7.amd64\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "F:\WinPython\python-3.6.7.amd64\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Users\MyName\AppData\Local\Microsoft\AppV\Client\Integration\some-ever-changing-hash\Root\VFS\ProgramFilesX86\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.14393 x86_64)

我一直在寻找不同的解决方案。我尝试手动指定 Chrome.exe 的路径,我添加了 sn-ps,如 add_argument("--disable-dev-shm-usage")options.add_argument("--no-sandbox") 以及使用单独的用户数据目录。当前代码如下所示

import os
from selenium import webdriver

###auto-find chrome path
def chrome_path_auto():
    for root, dirs, files in os.walk('C:/Users'):
        for name in files:
            if name == 'chrome.exe':
                return os.path.abspath(os.path.join(root, name))

options = webdriver.ChromeOptions()
chrome_driver_binary = "H:/My Documents/PYTHON/selenium_script/chromedriver/chromedriver.exe"
options.binary_location = chrome_path_auto()
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--user-data-dir=H:\\My Documents\\PYTHON\\selenium_script\\UserDataDir")
options.add_argument("--disable-extensions")
options.add_argument("--no-sandbox")

driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
driver.get('https://python.org')

Chrome的版本是71.0.3578.80,Chromedriver是2.45,应该是兼容的。我试过使用旧版本,但我只收到部分错误:DevToolsActivePort 文件不存在。 可能需要注意的是,我使用的远程桌面最近将操作系统从 Windows 7 更改为 Windows 10。在旧 Windows 上,一种非常相似的方法(使用 Chrome 和 Chromedriver 的旧版本)正在工作。有没有人遇到过类似的问题或可以想到替代解决方案?

如果还有什么需要请告诉我,我会尽量提供。

编辑 1.

我通过简单地将整个 Chrome 安装从原始文件夹 C:\Users\MyName\AppData\Local\Microsoft\AppV\Client\Integration\some-ever-changing-hash\Root\VFS\ProgramFilesX86\Google\Chrome\Application\chrome.exe 移动到共享磁盘 H:\Public\Chrome\Application 然后使用 binary_location 来解决这个问题。它可能与原始文件夹的根位置和缺乏管理员权限有关。

【问题讨论】:

    标签: python selenium selenium-chromedriver


    【解决方案1】:

    要解决 DevToolsActivePort 问题,请尝试添加以下参数:

    options.add_argument('--remote-debugging-port=45447')
    

    基本上,一旦端口设置为默认值 0 以外的其他值,就不需要检查 DevToolsActivePort 文件,从而避免您的问题。可以在此处找到有关 DevToolsActivePort 问题的更多详细信息:chromedriver_bug

    根据我对此问题的经验,当用户配置文件被复制到通常位于此处的 chrome 默认文件夹之外时,似乎会发生这种情况:

    C:\Users\用户名\AppData\Local\Google\Chrome\用户数据

    希望这会有所帮助!

    【讨论】:

    • 感谢您的帮助。不幸的是,这没有用,但我设法解决了问题。我会尽快写答案
    • @Seidhe 我真的可以用那个答案...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-07
    • 2017-04-26
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    相关资源
    最近更新 更多