5

Python script using Selenium can't create an instance of Chrome, despite the versions being correct and a UI being installed.

I've already taken a look at similar threads here, none of which appear to have solved the issue. The code works on Windows - it no longer works once I try to execute it on Linux. My intended goal is for it to open Chrome visually, and as such I am not looking for a solution that involves virtual displays.

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()

I have Google Chrome 75.0.3770.100 installed I also have ChromeDriver 75.0.3770.90

Here is the full traceback from the code:

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.)
Foo bar
  • 38
  • 2
Ethan Hill
  • 478
  • 2
  • 10
  • 24
  • 1
    This is actually not a duplicate issue, but seems to be an issue with ChromeDriver 75.0.3770.90. After downgrading to ChromeDriver 74.0.3729.6 all works fine for me. – Michael Reinsch Jul 01 '19 at 12:25

1 Answers1

2

This is for java, but I think it should work for you to: https://github.com/SeleniumHQ/selenium/issues/4961#issuecomment-346821657
It says that is is a permission issue. Try running your program as root.

Foo bar
  • 38
  • 2
  • I ran the execution command as root, but the console returned the same error. – Ethan Hill Jun 24 '19 at 16:14
  • Try adding the `--single-process` flag – Foo bar Jun 24 '19 at 16:22
  • If you look here: https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t, you will find that ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session. The arg you are using to stop it only works on Linux, so add these flags too: --disable-extensions, --disable-gpu, disable-infobars, start-maximized. – Foo bar Jun 24 '19 at 16:26
  • I tested the process twice, once with only the secondly mentioned flags (disable-extensions, etc...) and once with the --single-process flag enabled. Both times, the flags did not appear to fix the issue, and the error came back the same as from the original post. I'm on Ubuntu 18.04.2. – Ethan Hill Jun 24 '19 at 16:32
  • What Version python are you using? – Foo bar Jun 24 '19 at 23:13
  • Also try the Firefox drivers. https://github.com/mozilla/geckodriver/releases – Foo bar Jun 24 '19 at 23:14
  • Python 3.6 is my current version – Ethan Hill Jun 25 '19 at 16:25