我需要帮助才能使用 C# 升级到 geckodriver。我从这里下载了 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 有人可以帮我解决这个问题。
谢谢。