Solve Selenium WebDriverException executable needs to be in PATH error message
Guide to use Selenium with the appropriate web driver. In Selenium we have to choose a specific “browser” to use in our code, for example if we want to use Chrome:
from selenium.webdriver.chrome.webdriver import WebDriver browser = WebDriver()
- Using Chrome: selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
- Using WebKitWebDriver: selenium.common.exceptions.WebDriverException: Message: ‘WebKitWebDriver’ executable needs to be in PATH.
- Using Firefox: selenium.common.exceptions.GeckoDriverException: Message: GeckoWebDriver’ executable needs to be in PATH.
Solution
The generic steps to solve this are:
- download the desired browser driver executable
- make Selenium aware of the above driver location
1. First alternative: Automatic
The easiest way is to use webdriver-manager 1 which is a library “to automatically manage drivers for different browsers”.
1.1 Install
Install with the command: pip install webdriver_manager
pip install webdriver_manager Collecting webdriver-manager Downloading webdriver_manager-2.4.0-py2.py3-none-any.whl (13 kB) Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (from webdriver-manager) (2.22.0) Collecting crayons Using cached crayons-0.3.0-py2.py3-none-any.whl (4.6 kB) Collecting configparser Using cached configparser-5.0.0-py3-none-any.whl (22 kB) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,1.26,=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests->webdriver-manager) (1.25.6) Requirement already satisfied: chardet3.1.0,=3.0.2 in ~/.local/lib/python3.6/site-packages (from requests->webdriver-manager) (3.0.4) Requirement already satisfied: certifi=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests->webdriver-manager) (2019.9.11) Requirement already satisfied: idna2.9,>=2.5 in ~/.local/lib/python3.6/site-packages (from requests->webdriver-manager) (2.8) Requirement already satisfied: colorama in /usr/local/lib/python3.6/dist-packages (from crayons->webdriver-manager) (0.4.1) Installing collected packages: crayons, configparser, webdriver-manager Successfully installed configparser-5.0.0 crayons-0.3.0 webdriver-manager-2.4.0
1.2 Use
In your code use the right manager for Selenium’s webdriver:
pip install webdriver-manager from selenium import webdriver
And then Choose the right browser
Chrome
from webdriver_manager.chrome import ChromeDriverManager browser = webdriver.Chrome(ChromeDriverManager().install())
Firefox
from webdriver_manager.firefox import GeckoDriverManager browser = webdriver.Firefox(executable_path=GeckoDriverManager().install())
Internet Explorer
from webdriver_manager.microsoft import IEDriverManager browser = webdriver.Ie(IEDriverManager().install())
Edge
from webdriver_manager.microsoft import EdgeChromiumDriverManager browser = webdriver.Edge(EdgeChromiumDriverManager().install())
2. Second alternative: Manual
If you don’t want to use an external package you can do it manually with one of these options.
First, download the right driver consulting your desired browser’s driver at: https://selenium-python.readthedocs.io/api.html
Then, one of these two alternatives:
- add driver location to system’s path
- PATH=/location/of/browserdriver:$PATH
- driver = webdriver.Chrome(executable_path=’/location/of/firefoxdriver)
References
Marcelo Canina
I’m Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.