带有 selenium 3.0 的 Geckodriver 抛出 DriverServiceNotFoundException

Geckodriver with selenium 3.0 throws DriverServiceNotFoundException

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

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

尝试将其重命名为 'Wires' 但没有成功。在 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);

我将 Firefox 更新到版本 49.0.2,并将我的 selenium 驱动程序从 nuget 包更新到 3.0.0。将 Firefox 路径添加到系统路径变量。就是这样,我没有改变我的编码中的任何其他内容,即 Firefox 的声明。更新后我遇到了太多问题,例如等待和 System.Net.Web 异常。我需要修复我的一些测试用例,但它有效。