Unknown error: Chrome failed to start: exited abnormally

PythonPython 2.7TestingSelenium Chromedriver

Python Problem Overview


I am getting this error when I run my tests with Selenium using chromedriver.

selenium.common.exceptions.WebDriverException: Message:
unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.9.248316,platform=Linux 3.8.0-29-generic x86)

I did download google-chrome stable and also chromedriver and have used this code to start the browser.

driver = webdriver.Chrome('/usr/local/bin/chromedriver')

Any suggestions anyone? Thanks.

Python Solutions


Solution 1 - Python

For Linux :

Start the Display before start the Chrome. for more info click here

from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 800))  
display.start()
driver = webdriver.Chrome()

Solution 2 - Python

To help debug this problem you can use the service_log_path and service_args arguments to the selenium webdriver to see output from the chromedriver:

service_log_path = "{}/chromedriver.log".format(outputdir)
service_args = ['--verbose']
driver = webdriver.Chrome('/path/to/chromedriver',
        service_args=service_args,
        service_log_path=service_log_path)

I was getting this same exception message and found two ways to get past it; I'm not sure if the OP's problem is the same, but if not, the chromedriver log will hopefully help. Looking at my log, I discovered that the chromedriver (I tried 2.9 down to 2.6 while trying to fix this problem) decides which browser to run in a very unexpected way. In the directory where my chromedriver is located I have these files:

$ ls -l /path/to/
-rwx------  1 pjh grad_cs 5503600 Feb  3 00:07 chromedriver-2.9
drwxr-xr-x  3 pjh grad_cs    4096 Mar 28 15:51 chromium

When I invoke the chromedriver using the same python code as the OP:

driver = webdriver.Chrome('/path/to/chromedriver-2.9')

This leads to the exception message. In the chromedriver.log I found this message:

[1.043][INFO]: Launching chrome: /path/to/chromium ...

Unbelievable! The chromedriver is trying to use /path/to/chromium (which is not an executable file, but a directory containing source code) as the browser to execute! Apparently chromedriver tries to search the current directory for a browser to run before searching my PATH. So, one easy solution to this problem is to check the directory where the chromedriver is located for files/directories like chrome and chromium and move them to a different directory than the chromedriver.

A better solution is to explicitly tell selenium / chromedriver which browser to execute by using the chrome_options argument:

options = webdriver.ChromeOptions()
options.binary_location = '/opt/google/chrome/google-chrome'
service_log_path = "{}/chromedriver.log".format(outputdir)
service_args = ['--verbose']
driver = webdriver.Chrome('/path/to/chromedriver',
        chrome_options=options,
        service_args=service_args,
        service_log_path=service_log_path)

The chromedriver.log now shows:

[0.999][INFO]: Launching chrome: /opt/google/chrome/google-chrome ...

as expected.

Solution 3 - Python

An alternative solution of using a virtual display is the headless mode.

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--window-size=1420,1080')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=chrome_options)

Solution 4 - Python

If using Linux make sure you are not running as root. That what gave me the error.

Solution 5 - Python

Someone already mentioned about --no-sandbox option, but to expand on it: make sure, it's the first option you pass:

        System.setProperty("webdriver.chrome.driver",
                Paths.get("setups", driverFolder, driverFile).toAbsolutePath().toString());

        ChromeOptions options = new ChromeOptions();
        Map<String, Object> prefs = new HashMap<>();
        prefs.put("intl.accept_languages", "English");
        options.setExperimentalOption("prefs", prefs);

        options.addArguments("--no-sandbox");
        options.addArguments("--disable-features=VizDisplayCompositor");
        options.addArguments("--incognito");
        options.addArguments("enable-automation");
        options.addArguments("--headless");
        options.addArguments("--window-size=1920,1080");
        options.addArguments("--disable-gpu");
        options.addArguments("--disable-extensions");
        options.addArguments("--dns-prefetch-disable");
        options.setPageLoadStrategy(PageLoadStrategy.NORMAL);

        options.addArguments("enable-features=NetworkServiceInProcess");

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability("marionette", true);
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);

        WebDriver driver = new ChromeDriver(capabilities);
        driver.manage().timeouts().implicitlyWait(15, SECONDS);
        driver.manage().timeouts().pageLoadTimeout(15, SECONDS);

When it was added after other options, I got the error.

Solution 6 - Python

You may be able to fix this issue by making sure your version of chromedriver is right for the version of Chrome you have installed, which you can check here. You will also need to remove your current version of chromedriver before installing the new one, as described in Delete Chromedriver from Ubuntu

Solution 7 - Python

I was faced with the same issue and fixed it by installing Chrome in:

C:\Users\..\AppData\Local\Google\Chrome\Application

You can do this by running the Chrome Setup and saying no when prompted by the User Account Control.

Solution 8 - Python

This issue resolved using below steps

  1. Install Xvfb Centos 7 : yum install chromedriver chromium xorg-x11-server-Xvfb

  2. update chrome driver Centos 7 : wget https://chromedriver.storage.googleapis.com/2.40/chromedriver_linux64.zip

Solution 9 - Python

I got the same error when I crawl something using scrapy + selenium + chrome driver on Centos 7,and the method of following url solved my problem.

yum install mesa-libOSMesa-devel gnu-free-sans-fonts

refer:https://bugs.chromium.org/p/chromium/issues/detail?id=695212

Solution 10 - Python

Another solution for selenium webdriver is X virtual frame buffer:

with Xvfb() as _:
    timeout_request = ConfigTargetsManager.target_global_configs.get('timeout_request', 10)
    driver = webdriver.Chrome(executable_path=ConfigTargetsManager.target_global_configs.get('chrome_browser_path',
                                                                                             '/usr/lib/chromium-browser/chromedriver'))
    driver.get(url)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSahebView Question on Stackoverflow
Solution 1 - PythonVickyView Answer on Stackoverflow
Solution 2 - PythonpjhseaView Answer on Stackoverflow
Solution 3 - PythonSiyuView Answer on Stackoverflow
Solution 4 - PythonGuySoftView Answer on Stackoverflow
Solution 5 - PythonparsecerView Answer on Stackoverflow
Solution 6 - PythonmayaPapayaView Answer on Stackoverflow
Solution 7 - PythonquasarseekerView Answer on Stackoverflow
Solution 8 - Pythonpraveen kedarView Answer on Stackoverflow
Solution 9 - PythonxiaoliziView Answer on Stackoverflow
Solution 10 - PythonSalehView Answer on Stackoverflow