How to launch Chrome in Selenium correctly

Viewed 2784

I can not launch Chrome in Selenium.

driver=webdriver.Chrome()

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/usr/anaconda/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 67, in __init__
    desired_capabilities=desired_capabilities)

  File "/usr/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 87, in __init__
    self.start_session(desired_capabilities, browser_profile)

  File "/usr/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 141, in start_session
    'desiredCapabilities': desired_capabilities,
  File "/usr/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
    self.error_handler.check_response(response)

  File "/usr/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 181, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 3.19.8-100.fc20.x86_64 x86_64)

I use "chromedriver_linux64.zip 2017-10-03 21:09:52 3.90MB" from url.

4 Answers

You are using the current latest chromedriver 2.33 with Google Chrome 38.0.2125.104.

From the release notes, the support for this version is:

----------ChromeDriver v2.33 (2017-10-03)----------
Supports Chrome v60-62

Make sure also that you are using the latest stable version of selenium.

Furthermore, from Help WebDriver find the downloaded ChromeDriver executable, you should do one of these

  1. include the ChromeDriver location in your PATH environment variable
  2. (Python only) include the path to ChromeDriver when instantiating webdriver.Chrome (see sample below)

The error says it all :

File "<stdin>", line 1, in <module>

Seems the error occurs on the very first line which is as :

driver=webdriver.Chrome()

This is because here in this code block unless you import webdriver, the driver object is unable to properly initiate/handle the instance of WebBrowser i.e. Chrome Browser.

Solution :

While working with Selenium 3.x, ChromeDriver 2.33.x you need Chrome Browser v60-62 with Python 3.x bindings, and you have to do the following:

  • Download the chromedriver binary from this link.
  • Import the necessary modules
  • Provide the absolute path of the chromedriver binary in your system.
  • Below is the minimal code :

    //The Linux Example
    from selenium import webdriver
    driver = webdriver.Chrome(executable_path=r'/usr/bin/chromedriver')
    driver.get('https://www.google.co.in')
    print("Page Title is : %s" %driver.title)
    driver.quit()

    //The Windows Example
    from selenium import webdriver
    driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get('https://www.google.co.in')
    print("Page Title is : %s" %driver.title)
    driver.quit()

Update :

On a separate note as you are seeing WebDriverException: Message: unknown error: Chrome failed to start: crashed perform the following additional steps :

  • Uninstall Google Chrome from your system through Revo Uninstaller.
  • Run CCleaner to wipe out all the unwanted OS chores.
  • Take a system Reboot
  • Install latest official build of Google Chrome
  • Execute your Test.

If you're going to use an old version of Chrome - you will need to match the version of chromedriver to it. In your case you are using Chrome 38, which was last officially supported by ChromeDriver 2.13, which you can find here

If your users are using newer versions of Chrome, I would recommend updating your distro and installed chrome to match them.

Related