4
votes

I've converted an NUnit test project from .NET Framework to .NET Core. When I try to execute a Selenium test using Visual Studio, I am seeing this error:

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.

I've included the Selenium.WebDriver.ChromeDriver Nuget Package and chromedriver.exe appears in the output bin folder. Without having to set the ChromeDriver url as an environment variable, how do I get Visual Studio to find the file?

[Test]
public void Test()
{
   var driver = new ChromeDriver();
   driver.Url = "http://www.google.com";
}
3
While I don't want to do it as a solution, even adding chromedriver.exe to PATH variable doesn't work.infojolt
How do you instantiate the driver? Post your relevant code.JeffC
I believe installing it manually into your PATH is safer than relying on a 3rd party NuGet author package. Or downloading the exe from Google and putting it into your project manually. You can try using new ChromeDriver('.') which will look at the CWD where the program is executed from.Swimburger

3 Answers

4
votes

This happens because in .Net Core the NuGet packages are loaded from a global location instead of the packages folder in .NET Framework projects.

You can use the following and it will run correctly:

ChromeDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
1
votes

This works for me

        var currentDirectory = Directory.GetCurrentDirectory();
        var driverService = ChromeDriverService.CreateDefaultService(currentDirectory);        
        driverService.Start();
        var driver = new ChromeDriver(driverService);
0
votes

What i did when i had the problem was to set a var:

var driverDirectory = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);

And just pass it to ChromeDriver on creation.