WebDriverException: Message: unknown error: Chrome failed to start: crashed error using ChromeDriver Chrome through Selenium Python on Amazon Linux
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(chrome not reachable)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
As per the discussion in Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed, the expected default location of google-chrome on linux is:
/usr/bin/google-chrome
Note: For Linux systems, the ChromeDriver expects /usr/bin/google-chrome
to be a symlink to the actual Chrome binary.
So ideally, the following minimal code block should have worked:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = '/usr/bin/google-chrome'
driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver')
driver.get('http://www.google.com/')
But it seems, when you try to initiate a Chrome session manually, Segmentation fault occurs i.e. crashes as follows:
[ec2-user@ip-xxx-xx-xx-xxx bin]$ pwd
/usr/bin
[ec2-user@ip-xxx-xx-x-xxx bin]$ google-chrome
Segmentation fault
Segmentation fault
Segmentation fault (shortened as segfault
) or access violation is a fault or failure condition raised by hardware with memory protection, notifying an operating system that the software has attempted to access a restricted area of memory. The OS kernel will, in response, usually perform some corrective action, generally passing the fault on to the offending process (your script) by sending the process a signal.
In short, it’s a helper mechanism to restrict programs/scripts from corrupting the memory which does not belong to it. See more here.
Reason and Solutions
The pottential reasons and solutions are:
- Chrome is not at all installed within the system, so you have to install Chrome
-
Chrome is not installed at the default location, so you have to pass the correct location of chrome executable through
binary_location
property. - The symlink
/usr/bin/google-chrome
to the actual Chrome binary got corrupted, so you may have to create the symlink. - The user doesn't have required access rights
/usr/bin/google-chrome
, so you have provide the access rights.
Brent Heigold
Updated on June 30, 2022Comments
-
Brent Heigold almost 2 years
Just to show that I have done my due diligince, I have already either tried the suggested answers or at least read them over and tried to understand, for the following questions:
Selenium python library via docker, Chrome error failed to start: exited abnormally
Chrome crashes when using Selenium (No answer posted but I still looked it over)
How to fix "usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed" error in Linux? - For this one I substituted the '/usr/bin/google-chrome' with '/etc/alternatives/google-chrome', still didn't work.
python linux selenium: chrome not reachable
unknown error: Chrome failed to start: crashed(selenium ,headless mode)
python selenium: WebDriverException: Message: chrome not reachable
Selenium chrome failed to start
Selenium webdriver error Chrome failed to start
Python : Selenium - Message: unknown error: Chrome failed to start: exited abnormally
I am getting a common error that I have seen here on Stack Overflow, when running Selenium with Python on my Amazon Linux server I get the following results:
Traceback (most recent call last): File "test-selenium-chrome.py", line 15, in <module> driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver') # Optional argument, if not specified will search path.i File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ desired_capabilities=desired_capabilities) File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.7/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 (chrome not reachable) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Here is my code:
#!/usr/bin/python3 import time from selenium import webdriver from selenium.webdriver.chrome.options import Options from pyvirtualdisplay import Display options = Options() options.binary_location = '/usr/bin/google-chrome' options.add_argument('--disable-extensions') options.add_argument('--headless') options.add_argument('--no-sandbox') options.add_argument('--disable-dev-shm-usage') options.add_argument('--remote-debugging-port=9515') options.add_argument('--disable-setuid-sandbox') display = Display(visible=0, size=(800, 800)) display.start() driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver') # Optional argument, if not specified will seearch path.i driver.maximize_window() driver.get('http://www.google.com/') time.sleep(5) # Let the user actually see something! search_box = driver.find_element_by_name('q') search_box.send_keys('ChromeDriver') search_box.submit() time.sleep(5) # Let the user actually see something! driver.quit()
I am using Google Chrome version 79.0.3945.130, and the corresponding chromedriver version ChromeDriver 79.0.3945.36 as speicified in https://sites.google.com/a/chromium.org/chromedriver/downloads
Additional info, if I just run google-chrome from the command line, I get:
[ec2-user@ip-xxx-xx-xx-xxx bin]$ pwd /usr/bin [ec2-user@ip-xxx-xx-x-xxx bin]$ google-chrome Segmentation fault
Any help is greatly appreciated.
-
Brent Heigold about 4 yearsHi DebanjanB, I tried changing the ownership of /usr/bin/google-chrome to ec2-user:apache, and I still get the segmentation fault.
-
Brent Heigold about 4 yearsJust to do my due diligence, I have installed it as the solution suggested, with the path to the working symbolic link correctly specified in the code (options.binary_location = '/usr/bin/google-chrome')
-
undetected Selenium about 4 years@BrentHeigold Are you able to spin up a Chrome browsing context manually?
-
Brent Heigold about 4 yearsHi Debanjan, it's installed remotely on my AWS instance, so I can only run it command-line, and I get that same segmentation fault as described in my original question. Is that what you mean?
-
undetected Selenium about 4 years@BrentHeigold Seems something is still missing. If you can't achieve it manually due to OS kernel complaining about
segfault
, there's nothing much Selenium can do on top of it. Let me know if you have any further questions. -
Brent Heigold about 4 yearsOk sounds great, thanks for at least helping me narrow down my troubleshooting options.
-
dragonsfire almost 4 years@BrentHeigold did you get a solution that works? I'm finding I get this issue for some tests that run once I upgraded to v81 of chrome and chromedriver.
-
Brent Heigold almost 4 yearsHi dragonsfire, I did get a solution but it was a while ago so I don't remember what I did.
-
mouse_freak almost 3 years@dragonsfire Did you find the solution?
-
NorahKSakal over 2 yearsI received this error in GitHub actions and wrote an answer to it here stackoverflow.com/a/70341965/6697714 🌟 @mouse_freak