Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium through Python on VPS

So I have the exact same error as these posts

Selenium 'Chrome failed to start: exited abnormally' error

Unknown error: Chrome failed to start: exited abnormally

I tried what they recommended and it didn't work.

Here is my code

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))
display.start()

options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-extensions')
options.add_argument('--headless')
options.add_argument('--disable-gpu')

driver = webdriver.Chrome(chrome_options=options)
driver.get('http://nytimes.com')
print(driver.title)

driver.close()

And here is the full error message

Traceback (most recent call last):
  File "seleniumtest.py", line 13, in <module>
    driver = webdriver.Chrome(chrome_options=options)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-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
  (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.15.0-42-generic x86_64)

What the devil am I doing wrong? I'm running this on an ubuntu VPS on digitalocean.

like image 961
mcplums Avatar asked Feb 15 '19 18:02

mcplums


1 Answers

This error message...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux 4.15.0-42-generic x86_64)

...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.

There are exactly two incompatibility issues as discussed below.


disable-gpu

When Headless Chrome was first released as GA (General Availability) by Google Team the article Getting Started with Headless Chrome mentioned that :

--disable-gpu \                # Temporarily needed if running on Windows.

A note was added as :

Right now, you'll also want to include the --disable-gpu flag if you're running on Windows.

As per the discussion Headless: make --disable-gpu flag unnecessary it was clear that :

The --disable-gpu flag is no longer necessary on Linux or Mac OSX. It will also become unnecessary on Windows as soon as the bug SwiftShader fails an assert on Windows in headless mode is fixed. Now as this issue is marked fixed the argument --disable-gpu should be redundant now.

Note: You can find a detailed discussion in ERROR:gpu_process_transport_factory.cc(1007)-Lost UI shared context : while initializing Chrome browser through ChromeDriver in Headless mode


However, your main issue is the incompatibility between the version of the binaries you are using as follows:

  • You are using chromedriver=2.30
  • Release Notes of chromedriver=2.30 clearly mentions the following :

Supports Chrome v58-60

  • Your chrome version is unknown to us. Assuming you are using on of the latest Chrome releases either among:
    • Chrome version 71
    • Chrome version 72
    • Chrome version 73

So there is a clear mismatch between ChromeDriver v2.30 and the Chrome Browser v71-73

Solution

  • Depending on your Chrome Browser version upgrade ChromeDriver accordingly following the guidelines below:
    • If you are using Chrome version 73, you need to download ChromeDriver 73.0.3683.20
    • If you are using Chrome version 72, you need to download ChromeDriver 2.46 or ChromeDriver 72.0.3626.69
    • If you are using Chrome version 71, you need to download ChromeDriver 2.46 or ChromeDriver 71.0.3578.137
    • For older version of Chrome, see this discussion for the version of ChromeDriver that supports it.

References

You can find a couple of relevant discussions in:

  • OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally while executing tests through Selenium start on linux
  • WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium on debian server
  • Message: unknown error: Chrome failed to start: exited abnormally on AWS Cloud9 with Linux 4.9.85-38.58.amzn1.x86_64 x86_64
like image 167
undetected Selenium Avatar answered Oct 20 '22 23:10

undetected Selenium