当前位置: 首页 > 知识库问答 >
问题:

Selenium webdriver错误Chrome无法启动[重复]

锺离良哲
2023-03-14

我试图通过Selenium打开Chrome webdriver,但在初始化时出错。我收到的错误是:

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的路径,我添加了一些片段,如add_argument("--disable-dev-shm")options.add_argument("--no-沙盒")以及使用单独的user-data-dir。当前代码可以在下面看到

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 change hash\Root\VFS\ProgramFilesX86\Google\Chrome\Application\Chrome中移动,就成功地解决了这个问题。exe到共享磁盘H:\Public\Chrome\Application,然后使用二进制\u位置。它可能与原始文件夹的根位置和缺少管理员权限有关。

共有1个答案

太叔志尚
2023-03-14

要绕过devtoolsativeport问题,请尝试添加以下参数

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

基本上,一旦端口设置为默认值0以外的值,就不需要检查DevToolsActivePort文件,从而避免了您的问题。关于devtoolsativeport问题的更多细节可以在这里找到:chromedriver\u bug

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

C:\Users\username\AppData\Local\Google\Chrome\User Data

希望这能有所帮助!

 类似资料:
  • 问题内容: 由于这个问题,我已经呆了好几天,而且似乎找不到解决方案。无论我做什么,我都无法让chromedriver在我的机器上工作。我已经尝试了几乎所有我可以想象的设置。列举一些: Chrome 64位,Python 64位 Chrome 32位,Python 32位 Chrome 64位,Python 32位 Chrome 32位,Python 64位 我还尝试了不同版本的Chrome及其相应

  • 我在centos上运行无头chrome,无头chrome版本2.38和google-chrome-稳定版本67.0 chrome选项: 最后一行给出以下给定错误消息: 我已经验证了chrome和chromedriver版本,它是兼容的。无法理解为什么它没有在centos上运行?同样的代码在mac上运行良好 聚甲醛

  • 问题内容: 我正在尝试使用ChromeWebDriver在Chrome上测试我的应用程序,但是每次尝试都会出现以下异常: 在chromedriver.log中,我看到了 我正在使用: 镀铬36 ChromeWebDriver 2.10 Windows 7的 在Process Explorer中,我可以看到chromedriver.exe进程正在运行,但是没有打开任何窗口,几秒钟后,我得到了上面的异

  • 安装Katalon Studio v.5后。8.2对于同事的笔记本电脑,当尝试运行测试时,测试失败,出现此异常 测试失败,因为(的)(堆栈跟踪:com.kms.katalon.core.exception.StepFailedException:无法打开url为“”的浏览器(根本原因:org.openqa.selenium.WebDriverException:未知错误:chrome无法启动(驱动

  • 我有这个代码和一个执行中的问题(代码下的描述) 我使用: Ubuntu 14.04.5 LTS 当我创建RemoteWebDriver时,我得到以下错误:异常:未知错误:Chrome无法启动:崩溃 启动selenium服务器的命令 此方案的哪些部分可能是所述错误的原因?

  • 我试图将与一起使用,我为chromedriver到/usr/local/bin的路径创建了一个符号链接,但当我运行 我的错误是 它还会生成一个核心。******,一个包含五个随机数的核心文件点,大小超过200MB。 版本: 有谁能帮我找出问题出在哪里吗?