找不到.NET Core Selenium WebDriver [英] .NET Core Selenium WebDriver not found

查看:76
本文介绍了找不到.NET Core Selenium WebDriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将NNET测试项目从.NET Framework转换为.NET Core.当我尝试使用Visual Studio执行Selenium测试时,看到此错误:

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:chromedriver.exe文件在当前目录或目录中的目录中不存在PATH环境变量.该驱动程序可以在以下位置下载 http://chromedriver.storage.googleapis.com/index.html ..>

我已包含 Selenium.WebDriver.ChromeDriver Nuget软件包,并且 chromedriver.exe 出现在出纸槽文件夹中.无需将ChromeDriver URL设置为环境变量,如何让Visual Studio查找文件?

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

推荐答案

之所以会这样,是因为在.Net Core中,NuGet软件包是从全局位置加载的,而不是从.NET Framework项目中的packages文件夹加载的.

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

这篇关于找不到.NET Core Selenium WebDriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆