Borislav Hadzhiev
Mon Apr 18 2022·2 min read
Photo by Rachel Martin
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.
Open your terminal in your project's root directory and install the
webdriver-manager
module.
# 👇️ 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:
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
.
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.
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.