gpt4 book ai didi

selenium - .NET Core Selenium WebDriver 未找到

转载 作者:行者123 更新时间:2023-12-03 22:12:53 25 4
gpt4 key购买 nike

我已将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com