[python] Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed

Recently I switched computers and since then I can't launch chrome with selenium. I've also tried Firefox but the browser instance just doesn't launch.

from selenium import webdriver

d = webdriver.Chrome('/home/PycharmProjects/chromedriver')

d.get('https://www.google.nl/')

i get the following error:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.43.600233, platform=Linux 4.15.0-38-generic x86_64)

i have the latest chrome version and chromedriver installed

EDIT: After trying @b0sss solution i am getting the following error.

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (chrome not reachable)
  (The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so chromedriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-38-generic x86_64)

The answer is


Try to download HERE and use this latest chrome driver version.

https://sites.google.com/a/chromium.org/chromedriver/downloads

EDIT:

Try this:

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

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/PycharmProjects/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')

This error message...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /opt/google/chrome/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 WebBrowser i.e. Chrome Browser session.

Your main issue is the Chrome browser is not installed at the default location within your system.

The server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:

Chrome_binary_expected_location

1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.


Solution

In case you are using a Chrome executable in a non-standard location you have to override the Chrome binary location as follows:

  • Python Solution:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = Options()
    options.binary_location = "C:\\path\\to\\chrome.exe"    #chrome binary location specified here
    options.add_argument("--start-maximized") #open Browser in maximized mode
    options.add_argument("--no-sandbox") #bypass OS security model
    options.add_argument("--disable-dev-shm-usage") #overcome limited resource problems
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\path\to\chromedriver.exe')
    driver.get('http://google.com/')
    
  • Java Solution:

    System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
    ChromeOptions opt = new ChromeOptions();
    opt.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");  //chrome binary location specified here
    options.addArguments("start-maximized");
    options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
    options.setExperimentalOption("useAutomationExtension", false);
    WebDriver driver = new ChromeDriver(opt);
    driver.get("https://www.google.com/");
    

hope this helps someone. this worked for me on Ubuntu 18.10

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=chrome_options)
driver.get('http://www.google.com')
print('test')
driver.close()

I encountered the exact problem running on docker container (in build environment). After ssh into the container, I tried running the test manually and still encountered

(unknown error: DevToolsActivePort file doesn't exist)
     (The process started from chrome location /usr/bin/google-chrome-stable is 
      no longer running, so ChromeDriver is assuming that Chrome has crashed.)

When I tried running chrome locally /usr/bin/google-chrome-stable, error message

Running as root without --no-sandbox is not supported

I checked my ChromeOptions and it was missing --no-sandbox, which is why it couldn't spawn chrome.

capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
  chromeOptions: { args: %w(headless --no-sandbox disable-gpu window-size=1920,1080) }
)

I had a similar issue, and discovered that option arguments must be in a certain order. I am only aware of the two arguments that were required to get this working on my Ubuntu 18 machine. This sample code worked on my end:

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

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

d = webdriver.Chrome(executable_path=r'/home/PycharmProjects/chromedriver', chrome_options=options)
d.get('https://www.google.nl/')

in my case, the error was with www-data user but not with normal user on development. The error was a problem to initialize an x display for this user. So, the problem was resolved running my selenium test without opening a browser window, headless:

opts.set_headless(True)

Assuming that you already downloaded chromeDriver, this error is also occurs when already multiple chrome tabs are open.

If you close all tabs and run again, the error should clear up.


For RobotFramework

I solved it! using --no-sandbox

${chrome_options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
Call Method    ${chrome_options}    add_argument    test-type
Call Method    ${chrome_options}    add_argument    --disable-extensions
Call Method    ${chrome_options}    add_argument    --headless
Call Method    ${chrome_options}    add_argument    --disable-gpu
Call Method    ${chrome_options}    add_argument    --no-sandbox
Create Webdriver    Chrome    chrome_options=${chrome_options}

Instead of

Open Browser    about:blank    headlesschrome
Open Browser    about:blank    chrome

A simple solution that no one else has said but worked for me was not running without sudo or not as root.


This error has been happening randomly during my test runs over the last six months (still happens with Chrome 76 and Chromedriver 76) and only on Linux. On average one of every few hundred tests would fail, then the next test would run fine.

Unable to resolve the issue, in Python I wrapped the driver = webdriver.Chrome() in a try..except block in setUp() in my test case class that all my tests are derived from. If it hits the Webdriver exception it waits ten seconds and tries again.

It solved the issue I was having; not elegantly but it works.

from selenium import webdriver
from selenium.common.exceptions import WebDriverException

try:
    self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
except WebDriverException as e:
    print("\nChrome crashed on launch:")
    print(e)
    print("Trying again in 10 seconds..")
    sleep(10)
    self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
    print("Success!\n")
except Exception as e:
    raise Exception(e)

Make sure that both the chromedriver and google-chrome executable have execute permissions

sudo chmod -x "/usr/bin/chromedriver"

sudo chmod -x "/usr/bin/google-chrome"

I came across this error on linux environment. If not using headless then you will need

from sys import platform
    if platform != 'win32':
        from pyvirtualdisplay import Display
        display = Display(visible=0, size=(800, 600))
        display.start()

i faced the same problem but i solved it by moving the chromedriver to this path '/opt/google/chrome/'

and this code works correctly

from selenium.webdriver import Chrome
driver = Chrome('/opt/google/chrome/chromedrive')
driver.get('https://google.com')

i had same problem. I was run it on terminal with "sudo geany", you should run it without "sudo" just type on terminal "geany" and it is solved for me.


Questions with python tag:

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation Upgrade to python 3.8 using conda Unable to allocate array with shape and data type How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip How to prevent Google Colab from disconnecting? "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." when plotting figure with pyplot on Pycharm How to fix 'Object arrays cannot be loaded when allow_pickle=False' for imdb.load_data() function? "E: Unable to locate package python-pip" on Ubuntu 18.04 Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session' Jupyter Notebook not saving: '_xsrf' argument missing from post How to Install pip for python 3.7 on Ubuntu 18? Python: 'ModuleNotFoundError' when trying to import module from imported package OpenCV TypeError: Expected cv::UMat for argument 'src' - What is this? Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website How to setup virtual environment for Python in VS Code? Pylint "unresolved import" error in Visual Studio Code Pandas Merging 101 Numpy, multiply array with scalar What is the meaning of "Failed building wheel for X" in pip install? Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed Could not install packages due to an EnvironmentError: [Errno 13] OpenCV !_src.empty() in function 'cvtColor' error ConvergenceWarning: Liblinear failed to converge, increase the number of iterations How to downgrade python from 3.7 to 3.6 I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? Iterating over arrays in Python 3 How do I install opencv using pip? How do I install Python packages in Google's Colab? How do I use TensorFlow GPU? How to upgrade Python version to 3.7? How to resolve TypeError: can only concatenate str (not "int") to str How can I install a previous version of Python 3 in macOS using homebrew? Flask at first run: Do not use the development server in a production environment TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array What is the difference between Jupyter Notebook and JupyterLab? Pytesseract : "TesseractNotFound Error: tesseract is not installed or it's not in your path", how do I fix this? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'" How do I resolve a TesseractNotFoundError? Trying to merge 2 dataframes but get ValueError Authentication plugin 'caching_sha2_password' is not supported Python Pandas User Warning: Sorting because non-concatenation axis is not aligned

Questions with selenium tag:

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81 session not created: This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser Class has been compiled by a more recent version of the Java Environment How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium? How to make Firefox headless programmatically in Selenium with Python? element not interactable exception in selenium web automation Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click How do you fix the "element not interactable" exception? Python Selenium Chrome Webdriver Scrolling to element using webdriver? Which ChromeDriver version is compatible with which Chrome Browser version? selenium - chromedriver executable needs to be in PATH Selenium using Python - Geckodriver executable needs to be in PATH Only local connections are allowed Chrome and Selenium webdriver Selenium using Java - The path to the driver executable must be set by the webdriver.gecko.driver system property Check if element is clickable in Selenium Java XPath: difference between dot and text() How to use the gecko executable with Selenium Selenium 2.53 not working on Firefox 47 SyntaxError: Use of const in strict mode? How to set "value" to input web element using selenium? How to open a link in new tab (chrome) using Selenium WebDriver? Can a website detect when you are using Selenium with chromedriver? What is the difference between getText() and getAttribute() in Selenium WebDriver? ImportError: No module named 'selenium' How to click a href link using Selenium How to get attribute of element from Selenium? Selenium Finding elements by class name in python Change user-agent for Selenium web-driver Error message: "'chromedriver' executable needs to be available in the path" Open web in new tab Selenium + Python Wait until page is loaded with Selenium WebDriver for Python Set value of input instead of sendKeys() - Selenium WebDriver nodejs Error: org.testng.TestNGException: Cannot find class in classpath: EmpClass Capturing browser logs with Selenium WebDriver using Java Get all child elements How to deal with certificates using Selenium? How to handle authentication popup with Selenium WebDriver using Java Find elements inside forms and iframe using Java and Selenium WebDriver How to write multiple conditions of if-statement in Robot Framework How to use XPath preceding-sibling correctly How can I control Chromedriver open window size? Where to find 64 bit version of chromedriver.exe for Selenium WebDriver? Selenium and xPath - locating a link by containing text How to read Data from Excel sheet in selenium webdriver What is difference between Implicit wait and Explicit wait in Selenium WebDriver? How to verify an XPath expression in Chrome Developers tool or Firefox's Firebug? unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.9

Questions with google-chrome tag:

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81 SameSite warning Chrome 77 What's the net::ERR_HTTP2_PROTOCOL_ERROR about? session not created: This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium Jupyter Notebook not saving: '_xsrf' argument missing from post How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue? Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser How to make audio autoplay on chrome How to handle "Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first." on Desktop with Chrome 66? how to open Jupyter notebook in chrome on windows Access Control Origin Header error using Axios in React Web throwing error in Chrome Invalid self signed SSL cert - "Subject Alternative Name Missing" Chrome violation : [Violation] Handler took 83ms of runtime Getting Error "Form submission canceled because the form is not connected" Violation Long running JavaScript task took xx ms Which ChromeDriver version is compatible with which Chrome Browser version? In Chrome 55, prevent showing Download button for HTML 5 video Why does this "Slow network detected..." log appear in Chrome? A Parser-blocking, cross-origin script is invoked via document.write - how to circumvent it? Disable Chrome strict MIME type checking Cannot open local file - Chrome: Not allowed to load local resource Chrome dev tools fails to show response even the content returned has header Content-Type:text/html; charset=UTF-8 "Uncaught TypeError: a.indexOf is not a function" error when opening new foundation project Is there any way to debug chrome in any IOS device net::ERR_INSECURE_RESPONSE in Chrome How to change the locale in chrome browser What does ==$0 (double equals dollar zero) mean in Chrome Developer Tools? How to prevent "The play() request was interrupted by a call to pause()" error? Disable-web-security in Chrome 48+ When you use 'badidea' or 'thisisunsafe' to bypass a Chrome certificate/HSTS error, does it only apply for the current site? How to open a link in new tab (chrome) using Selenium WebDriver? How to open google chrome from terminal? HTML 5 Video "autoplay" not automatically starting in CHROME Chrome / Safari not filling 100% height of flex parent Chrome:The website uses HSTS. Network errors...this page will probably work later Can a website detect when you are using Selenium with chromedriver? What is the "Upgrade-Insecure-Requests" HTTP header? require is not defined? Node.js Where does Chrome store cookies? Chrome net::ERR_INCOMPLETE_CHUNKED_ENCODING error Understanding Chrome network log "Stalled" state Edit and replay XHR chrome/firefox etc? Force hide address bar in Chrome on Android Google Chrome forcing download of "f.txt" file SSL cert "err_cert_authority_invalid" on mobile chrome only Run chrome in fullscreen mode on Windows "Proxy server connection failed" in google chrome How do I execute .js files locally in my browser? Google Chrome: This setting is enforced by your administrator

Questions with selenium-webdriver tag:

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81 Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium? How to make Firefox headless programmatically in Selenium with Python? Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click How do you fix the "element not interactable" exception? Scrolling to element using webdriver? Only local connections are allowed Chrome and Selenium webdriver Check if element is clickable in Selenium Java Selenium 2.53 not working on Firefox 47 SyntaxError: Use of const in strict mode? Selenium -- How to wait until page is completely loaded How to set "value" to input web element using selenium? How to open a link in new tab (chrome) using Selenium WebDriver? What is the difference between getText() and getAttribute() in Selenium WebDriver? How to get attribute of element from Selenium? Selenium Finding elements by class name in python What is the difference between absolute and relative xpaths? Which is preferred in Selenium automation testing? Press TAB and then ENTER key in Selenium WebDriver Set value of input instead of sendKeys() - Selenium WebDriver nodejs Error: org.testng.TestNGException: Cannot find class in classpath: EmpClass Capturing browser logs with Selenium WebDriver using Java Get all child elements How to deal with certificates using Selenium? How to handle authentication popup with Selenium WebDriver using Java Where to find 64 bit version of chromedriver.exe for Selenium WebDriver? Selenium and xPath - locating a link by containing text What is difference between Implicit wait and Explicit wait in Selenium WebDriver? How to verify an XPath expression in Chrome Developers tool or Firefox's Firebug? unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.9 IE Driver download location Link for Selenium Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds How to click on hidden element in Selenium WebDriver? How to gettext() of an element in Selenium Webdriver How to select the Date Picker In Selenium WebDriver How to use regex in XPath "contains" function Select a date from date picker using Selenium webdriver python selenium click on button release Selenium chromedriver.exe from memory How can I scroll a web page using selenium webdriver in python? Cannot find firefox binary in PATH. Make sure firefox is installed How to wait until an element is present in Selenium? Selenium WebDriver can't find element by link text How to select a dropdown value in Selenium WebDriver using Java How to select option in drop down using Capybara How to identify and switch to the frame in selenium webdriver when frame does not have id Call a Class From another class How to handle Pop-up in Selenium WebDriver using Java sendKeys() in Selenium web driver

Questions with selenium-chromedriver tag:

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81 session not created: This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium? Python Selenium Chrome Webdriver selenium - chromedriver executable needs to be in PATH Only local connections are allowed Chrome and Selenium webdriver How to set "value" to input web element using selenium? Can a website detect when you are using Selenium with chromedriver? Error message: "'chromedriver' executable needs to be available in the path" When running WebDriver with Chrome browser, getting message, "Only local connections are allowed" even though browser launches properly How can I control Chromedriver open window size? Where to find 64 bit version of chromedriver.exe for Selenium WebDriver? Disable developer mode extensions pop up in Chrome unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.9 release Selenium chromedriver.exe from memory How to run Selenium WebDriver test cases in Chrome How do I pass options to the Selenium Chrome driver using Python? How to Maximize window in chrome using webDriver (python)