Mon Apr 18 2022·2 min read
Photo by Tamara Bellis
To solve the Selenium error "WebDriverException: Message: 'geckodriver'
executable needs to be in PATH", install and import the
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
# 👇️ 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.firefox import GeckoDriverManager driver = webdriver.Firefox(executable_path=GeckoDriverManager().install()) driver.get("http://www.python.org") driver.close()
The example shows how to use the
webdriver-manager module with the
browser, but it can be used with all other browsers as well.
Here is an example that uses the module with
from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(ChromeDriverManager().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_managermodule 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
on the specific driver manager and it just works.