.NET Core Selenium WebDriver not found

南笙酒味 提交于 2021-01-27 06:40:08

问题


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";
}

回答1:


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));



回答2:


This works for me

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



回答3:


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.



来源:https://stackoverflow.com/questions/52925604/net-core-selenium-webdriver-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!