selenium - .NET Core Selenium WebDriver 未找到

标签 selenium .net-core selenium-chromedriver

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

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 找到该文件?
[Test]
public void Test()
{
   var driver = new ChromeDriver();
   driver.Url = "http://www.google.com";
}

最佳答案

发生这种情况是因为在 .Net Core 中,NuGet 包是从全局位置而不是 .NET Framework 项目中的包文件夹加载的。

您可以使用以下内容,它将正确运行:

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

关于selenium - .NET Core Selenium WebDriver 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52925604/

相关文章:

selenium - 等到可见和等到位于 Selenium 之间有什么区别

linux - 带有 PhantomJS 的 WebDriverJS 可以在 OSX 上运行,但不能在 Linux 上运行

python - 使用 Python 转义 XPath 文字

c# - 在 .NET 4.5.2 控制台应用程序中使用 .NET Core 库

python - 如何在 python 中使用 selenium 中预定义的 chrome 配置文件?

selenium - 无法使用 chromedriver 创建新的远程 session

java - Selenium HtmlUnitDriver 中的未知主机

.net - Azure Blob 存储-container.GetBlobsByHierarchyAsync-不返回结果

c# - DataMember 属性在 dotnet core 3.0 中不受尊重

使用静态 WebDriver 实例的 java.lang.NullPointerException