【问题标题】:WebDriverException: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) [duplicate]WebDriverException:Chrome 启动失败:异常退出(未知错误:DevToolsActivePort 文件不存在)[重复]
【发布时间】:2019-11-06 11:31:22
【问题描述】:

尽管版本正确且安装了 UI,但使用 Selenium 的 Python 脚本无法创建 Chrome 实例。

我已经在这里查看了类似的线程,但似乎都没有解决问题。该代码适用于 Windows - 一旦我尝试在 Linux 上执行它,它就不再适用。我的预期目标是让它以可视方式打开 Chrome,因此我不是在寻找涉及虚拟显示器的解决方案。

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

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

driver = webdriver.Chrome('/home/ethan/chromedriver', chrome_options=options)
driver.set_window_size(1024, 600)
driver.maximize_window()

我已安装 Google Chrome 75.0.3770.100 我也有 ChromeDriver 75.0.3770.90

这是代码的完整回溯:

File "cm_update_01.py", line 114, in <module>
    if __name__ == "__main__": main()
  File "cm_update_01.py", line 24, in main
    with open(fetch_file()) as f:
  File "cm_update_01.py", line 75, in fetch_file
    driver = webdriver.Chrome('/home/ethan/chromedriver', chrome_options=options)
  File "/home/ethan/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/ethan/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/ethan/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/ethan/.local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/ethan/.local/lib/python3.6/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: exited abnormally
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

【问题讨论】:

  • 这实际上不是重复的问题,但似乎是 ChromeDriver 75.0.3770.90 的问题。降级到 ChromeDriver 74.0.3729.6 后对我来说一切正常。

标签: python python-3.x selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

这适用于 java,但我认为它应该适合您: https://github.com/SeleniumHQ/selenium/issues/4961#issuecomment-346821657
它说这是一个许可问题。尝试以 root 身份运行您的程序。

【讨论】:

  • 我以root身份运行执行命令,但控制台返回同样的错误。
  • 尝试添加--single-process标志
  • 如果您看这里:stackoverflow.com/questions/50642308/…,您会发现 ChromeDriver 无法启动/生成新的 WebBrowser,即 Chrome 浏览器会话。您用来停止它的 arg 仅适用于 Linux,因此也要添加以下标志:--disable-extensions、--disable-gpu、disable-infobars、start-maximized。
  • 我对该过程进行了两次测试,一次只使用了第二次提到的标志(禁用扩展等),一次启用了 --single-process 标志。两次,标志似乎都没有解决问题,并且错误返回与原始帖子相同。我在 Ubuntu 18.04.2 上。
  • 你用的是什么版本的python?
猜你喜欢
  • 2020-05-03
  • 2023-02-07
  • 2015-08-14
  • 2019-05-15
  • 1970-01-01
  • 2021-05-03
  • 1970-01-01
  • 2017-06-17
  • 1970-01-01
相关资源
最近更新 更多