gpt4 book ai didi

c# - 带有 selenium 3.0 的 Geckodriver 抛出 DriverServiceNotFoundException

转载 作者:太空宇宙 更新时间:2023-11-03 12:37:42 25 4
gpt4 key购买 nike

我需要帮助才能使用 C# 升级到 geckodriver。我从 here 下载了 geckodriver .因为我在 windows 10 64bit 上,所以下载了 windows 64bit 版本。将驱动程序复制到我的项目位置。

Environment.SetEnvironmentVariable("webdriver.gecko.driver", @"C:\Git\AutomationTest\Drivers\geckodriver.exe");
FirefoxDriverService driverService = FirefoxDriverService.CreateDefaultService();
driverService.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
driverService.HideCommandPromptWindow = true;
driverService.SuppressInitialDiagnosticInformation = true;
driver = new FirefoxDriver(driverService, new FirefoxOptions(), TimeSpan.FromMilliseconds(600));

它抛出错误:

Initialization method UnitTestProject1.UnitTest1.Init threw exception. OpenQA.Selenium.DriverServiceNotFoundException: OpenQA.Selenium.DriverServiceNotFoundException: The geckodriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at https://github.com/mozilla/geckodriver/releases..
Result StackTrace:
at OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String executableName, Uri downloadUrl)
at OpenQA.Selenium.Firefox.FirefoxDriverService.CreateDefaultService()
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions options)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor()
at UnitTestProject1.UnitTest1.Init()

尝试将其重命名为“电线”但没有成功。在 SO 上搜索了很多问题,没有找到 Selenium 3.0 的解决方案。

将具有驱动程序的文件夹的路径添加到系统变量路径并尝试使用DesiredCapabilities

DesiredCapabilities cap = DesiredCapabilities.Firefox();
cap.SetCapability("marionette", true);
var driver = new RemoteWebDriver(cap);

使用 Selenium 3.0、FF 47.0.1、gecko v0.11.1谁能帮我解决这个问题。

谢谢。

最佳答案

试试这个:

FirefoxDriverService service = FirefoxDriverService.CreateDefaultService("C:\Git\AutomationTest\Drivers");

IWebDriver driver = new FirefoxDriver(service);

关于c# - 带有 selenium 3.0 的 Geckodriver 抛出 DriverServiceNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40283174/

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