Message: 'chromedriver' executable needs to be in PATH

avatar
Borislav Hadzhiev

Last updated: Apr 8, 2024
5 min

banner

# Table of Contents

  1. Message: 'chromedriver' executable needs to be in PATH
  2. Message: session not created: This version of ChromeDriver only supports Chrome version 102

# Message: 'chromedriver' executable needs to be in PATH

To solve the Selenium error "WebDriverException: Message: 'chromedriver' executable needs to be in PATH", install and import the webdriver-manager module by running pip install webdriver-manager.

The module simplifies management of binary drivers for different browsers.

chromedriver executable needs to be in path

# Install the webdriver-manager module

Open your terminal in your project's root directory and install the webdriver-manager module.

shell
# ๐Ÿ‘‡๏ธ In a virtual environment or using Python 2 pip install webdriver-manager # ๐Ÿ‘‡๏ธ For python 3 (could also be pip3.10 depending on your version) pip3 install webdriver-manager # ๐Ÿ‘‡๏ธ If you get a permissions error sudo pip3 install webdriver-manager # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install webdriver-manager # ๐Ÿ‘‡๏ธ For python 3 (could also be pip3.10 depending on your version) python3 -m pip install webdriver-manager # ๐Ÿ‘‡๏ธ For Anaconda conda install -c conda-forge webdriver-manager

After you install the webdriver-manager package, you can import it and use it as follows.

main.py
# โœ… for selenium version 4 from selenium import webdriver from selenium.webdriver.chrome.service import Service as ChromeService from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(service=ChromeService( ChromeDriverManager().install())) driver.get("http://www.python.org") driver.close()

The code sample above should be used for selenium version 4.

If you use selenium version 3, use the following code sample instead.

main.py
# โœ… for selenium version 3 from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(ChromeDriverManager().install()) driver.get("http://www.python.org") driver.close()

If you need to check your selenium version, issue the pip show selenium command.

shell
pip show selenium pip3 show selenium

# Using the webdriver-manager package with Chromium

The example shows how to use the webdriver-manager module with the Chrome browser, but it can be used with all other browsers as well.

Here is an example that uses the module with Chromium.

main.py
# โœ… for selenium 4 from selenium import webdriver from selenium.webdriver.chrome.service import Service as ChromiumService from webdriver_manager.chrome import ChromeDriverManager from webdriver_manager.core.utils import ChromeType driver = webdriver.Chrome(service=ChromiumService( ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())) driver.get("http://www.python.org") driver.close()

And here is an example that runs the Chromium browser for selenium version 3.

main.py
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from webdriver_manager.core.utils import ChromeType driver = webdriver.Chrome(ChromeDriverManager( chrome_type=ChromeType.CHROMIUM).install()) driver.get("http://www.python.org") driver.close()

You can view examples of how to use the webdriver-manager module with all other browsers in the official pypi page.

The webdriver_manager module provides a way to automatically manage drivers for different browsers.

If you decide to not use the module, you have to download the binary for the drivers, unzip them on your PC and set the path to the driver when using the class from the selenium module.

By using the webdriver_manager module, we can just call the install method on the specific driver manager and it just works.

# Downloading ChromeDriver manually

If you want to download ChromeDriver manually instead of using webdriver_manager, follow the instructions:

  1. Visit the ChromeDriver Downloads package and under current releases click on the download link for your version of Chrome.

download chromedriver

  1. Once you click on the link, make sure to download the correct zip file for your operating system. There are files for Linux, macOS and Windows.
  2. Extract the zip file.
  3. You can either place the chromedriver.exe file in a directory that is already listed in your PATH, or you can place the driver in a directory and add the directory to your PATH.

To see what directories are already on your PATH, issue the following command in bash or zsh.

bash_or_zsh
echo $PATH

And the following command on Windows.

cmd
echo %PATH%

If the chromedriver.exe file is not in a directory that's already on PATH, add the directory to your PATH with the following command.

For bash shell:

bash
echo 'export PATH=$PATH:/path/to/driver' >> ~/.bash_profile source ~/.bash_profile

For zsh shell:

zsh
echo 'export PATH=$PATH:/path/to/driver' >> ~/.zshenv source ~/.zshenv

For Windows:

cmd
setx PATH "%PATH%;C:\WebDriver\bin"

You can test if you have added chromedriver correctly to your PATH by issuing the following command.

For bash or zsh:

shell
chromedriver

For Windows:

cmd
chromedriver.exe

If you aren't able to start the Chrome browser without specifying a path, try explicitly setting the path to the chromedriver.exe file.

main.py
import time from selenium import webdriver from selenium.webdriver.chrome.service import Service driver = webdriver.Chrome(service=Service( r'C:/Users/bobbyhadz/Documents/chromedriver.exe')) driver.get("http://www.python.org") time.sleep(2) driver.close()

Make sure to specify the correct path to your chromedriver.exe executable.

You can also follow the official selenium guide to set up chromedriver.

# Starting with version 4.6, Selenium comes with batteries included

In November 2022, the selenium team introduced Selenium version 4.6.

The version comes with the batteries included and only requires you to have Chrome installed.

The Selenium package now configures the driver for Chrome if it isn't present on the PATH environment variable.

If your selenium version is older than 4.6, update the package by running the following command.

shell
pip install selenium --upgrade pip3 install selenium --upgrade # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install selenium --upgrade python3 -m pip install selenium --upgrade

You can use the pip show command to check your selenium version.

shell
pip show selenium

If you already have the browser driver installed on your machine, the feature of automatically setting up browser drivers will be ignored.

The feature is only in effect if selenium cannot find the browser drivers present on your PATH environment variable.

# Message: session not created: This version of ChromeDriver only supports Chrome version 102

The error "Message: session not created: This version of ChromeDriver only supports Chrome version 102" occurs when your version of ChromeDriver doesn't support your installed version of Chrome.

To solve the error install and use the webdriver-manager package which automatically uses the correct ChromeDriver version.

shell
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 102 Current browser version is 100.0.4896.127 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe

Open your terminal in your project's root directory and run the following command.

shell
pip install webdriver-manager selenium # ๐Ÿ‘‡๏ธ For Python 3 pip3 install webdriver-manager selenium # ๐Ÿ‘‡๏ธ If you get a permissions error sudo pip3 install webdriver-manager selenium # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install webdriver-manager selenium # ๐Ÿ‘‡๏ธ For python 3 python3 -m pip install webdriver-manager selenium # ๐Ÿ‘‡๏ธ Using py alias py -m pip install webdriver-manager selenium # ๐Ÿ‘‡๏ธ Alternative if you get a permissions error pip install webdriver-manager selenium --user

The command installs the webdriver-manager package which simplifies the management of binary drivers for different browsers.

Here is an example of using the Webdriver manager with Selenium 4.

main.py
import time from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) driver.get("http://www.python.org") time.sleep(2) driver.close()

And here is an example of how to use the Webdriver manager with Selenium 3.

main.py
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(ChromeDriverManager().install())

You can check how to use the Webdriver manager package with Selenium v3 and v4 for all browser types in this section of the package's pypi page.

Alternatively, you can use the chromedriver-autoinstaller package which automatically downloads and installs ChromeDriver that supports the currently installed version of Chrome.

Open your terminal in your project's root directory and run the following command.

shell
pip install chromedriver-autoinstaller # ๐Ÿ‘‡๏ธ For Python 3 pip3 install chromedriver-autoinstaller # ๐Ÿ‘‡๏ธ If you get a permissions error sudo pip3 install chromedriver-autoinstaller # ๐Ÿ‘‡๏ธ If you don't have pip in your PATH environment variable python -m pip install chromedriver-autoinstaller # ๐Ÿ‘‡๏ธ For python 3 python3 -m pip install chromedriver-autoinstaller # ๐Ÿ‘‡๏ธ Using py alias py -m pip install chromedriver-autoinstaller # ๐Ÿ‘‡๏ธ Alternative if you get a permissions error pip install chromedriver-autoinstaller --user

Now you only have to import chromedriver_autoinstaller in your module.

main.py
import time import chromedriver_autoinstaller from selenium import webdriver chromedriver_autoinstaller.install() driver = webdriver.Chrome() driver.get("http://www.python.org") time.sleep(2) driver.close()

The chromedriver-autoinstaller package automatically downloads and installs ChromeDriver for your version of Chrome.

I've also written an article on Message: 'geckodriver' executable needs to be in PATH.

The error occurs when using Firefox with selenium.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev