WebDriverException:Chrome无法启动:异常退出(未知错误:DevToolsActivePort文件不存在)

时间:2019-06-24 16:03:40

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

尽管版本正确且已安装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.)

1 个答案:

答案 0 :(得分:0)

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