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

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

问题描述

我已将 NUnit 测试项目从 .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.>

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.

我已经包含了 Selenium.WebDriver.ChromeDriver Nuget 包并且 chromedriver.exe 出现在输出 bin 文件夹中.无需将 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 项目中的包文件夹加载.

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天全站免登陆