Message: 'chromedriver' executable needs to be in PATH

avatar

Borislav Hadzhiev

Last updated: Apr 18, 2022

banner

Photo from Unsplash

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

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 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 like so:

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

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
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from webdriver_manager.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 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.

Conclusion #

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.

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.