I’m trying to use Selenium with the ChromeDriver and I’m running into the following exception:
Unhandled Exception: OpenQA.Selenium.DriverServiceNotFoundException: The chromedriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html
The simplest solution is to install the Selenium.Chrome.WebDriver nuget package. This results in the ChromeDriver.exe being put into your build directory.
- Right-click your project > click Manage NuGet Packages
- Install the Selenium.Chrome.WebDriver nuget package
Note: You can always specify the chromedriver.exe in the constructor, but this requires you to have it installed already. Installing via nuget is a simpler approach.
Manually downloading the right chromedriver
Problem – chromedriver version incompatibility
When you attempt to use a version of chromedriver that’s incompatible with the browser you’re targeting, you’ll run into error messages like the following:
System.InvalidOperationException: session not created: Chrome version must be between 70 and 73
(Driver info: chromedriver=2.45.615291
System.InvalidOperationException: session not created: This version of ChromeDriver only supports Chrome version 85 (SessionNotCreated)
Solution – download the right chromedriver manually
At the current time, the latest version of Chrome is v89, and the Selenium.Chrome.WebDriver nuget package currently doesn’t contain the latest version.
Instead of getting the chromedriver from Selenium.Chrome.WebDriver, you can manually download whatever chromedriver version you need and add it to your project.
- Download the right chromedriver.exe version you need from Chromium ChromeDriver downloads.
- Add chromedriver.exe into your project and make it output to the build directory:
- Specify the chromedriver directory by passing in the chromeDriverDirectory, like this:
Code language: C# (cs)
var options = new ChromeOptions(); options.BinaryLocation = @"C:\Chrome\v76\chrome.exe"; IWebDriver driver = new ChromeDriver(chromeDriverDirectory: @"chromedrivers\v76", options); driver.Navigate().GoToUrl("https://www.google.com");
Note: You can deal with multiple versions of Chrome / ChromeDriver at the same time using this approach.