Unable to Locate Driver Error
Historically, this is the most common error beginning Selenium users get when trying to run code for the first time:
Likely cause
Through WebDriver, Selenium supports all major browsers. In order to drive the requested browser, Selenium needs to send commands to it via an executable driver. This error means the necessary driver could not be found by any of the means Selenium attempts to use.
Possible solutions
There are several ways to ensure Selenium gets the driver it needs.
Use the latest version of Selenium
As of Selenium 4.6, Selenium downloads the correct driver for you. You shouldn’t need to do anything. If you are using the latest version of Selenium and you are getting an error, please turn on logging and file a bug report with that information.
If you want to read more information about how Selenium manages driver downloads for you, you can read about the Selenium Manager.
Use the PATH
environment variable
This option first requires manually downloading the driver.
This is a flexible option to change location of drivers without having to update your code, and will work on multiple machines without requiring that each machine put the drivers in the same place.
You can either place the drivers in a directory that is already listed in PATH
,
or you can place them in a directory and add it to PATH
.
To see what directories are already on PATH
, open a Terminal and execute:
echo $PATH
If the location to your driver is not already in a directory listed, you can add a new directory to PATH:
echo 'export PATH=$PATH:/path/to/driver' >> ~/.bash_profile
source ~/.bash_profile
You can test if it has been added correctly by checking the version of the driver:
chromedriver --version
To see what directories are already on PATH
, open a Terminal and execute:
echo $PATH
If the location to your driver is not already in a directory listed, you can add a new directory to PATH:
echo 'export PATH=$PATH:/path/to/driver' >> ~/.zshenv
source ~/.zshenv
You can test if it has been added correctly by checking the version of the driver:
chromedriver --version
To see what directories are already on PATH
, open a Command Prompt and execute:
echo %PATH%
If the location to your driver is not already in a directory listed, you can add a new directory to PATH:
setx PATH "%PATH%;C:\WebDriver\bin"
You can test if it has been added correctly by checking the version of the driver:
chromedriver.exe --version
Specify the location of the driver
If you cannot upgrade to the latest version of Selenium, you do not want Selenium to download drivers for you, and you can’t figure out the environment variables, you can specify the location of the driver in the Service object.
You first need to download the desired driver,
then create an instance of the applicable Service
class and
set the path.
Specifying the location in the code itself has the advantage of not needing to figure out Environment Variables on your system, but has the drawback of making the code less flexible.
Driver management libraries
Before Selenium managed drivers itself, other projects were created to do so for you.
If you can’t use Selenium Manager because you are using an older version of Selenium (please upgrade), or need an advanced feature not yet implemented by Selenium Manager, you might try one of these tools to keep your drivers automatically updated:
- WebDriverManager (Java)
- WebDriver Manager (Python)
- WebDriver Manager Package (.NET)
- webdrivers gem (Ruby)
Download the driver
Navegador | OS Suportado | Mantido por | Download | Rastreador de Problemas |
---|---|---|---|---|
Chromium/Chrome | Windows/macOS/Linux | Downloads | Problemas | |
Firefox | Windows/macOS/Linux | Mozilla | Downloads | Problemas |
Edge | Windows/macOS/Linux | Microsoft | Downloads | Problemas |
Internet Explorer | Windows | Projeto Selenium | Downloads | Problemas |
Safari | macOS High Sierra e superiores | Apple | Integrado no Sistema | Problemas |
Nota: O Opera driver já não inclui as funcionalidades mais recentes do Selenium e oficialmente deixou de ser suportado.