c# - 远程 Webdriver Chrome 抛出 "path to the driver executable"错误

标签 c# webdriver remotewebdriver

嗨,当我使用下面的代码时

IWebDriver _webDriver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),
                DesiredCapabilities.Chrome());

我得到以下错误

System.InvalidOperationException : The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list TearDown : System.NullReferenceException : Object reference not set to an instance of an object. at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities) at Testframework.Browser.RemoteGoto(String browser, String url) in Browser.cs: line 86 at Testframework.CommonAction.RemoteBrowser(String browser) in CommonAction.cs: line 70 at Test.RegistrationTest.InvalidRegistrationTest(String browser, String username, String password, String confirmPassword, String securityQuestion, String securityAnswer, String errorMessageText, String firstname, String lastname) in RegistrationTest.cs: line 50 --TearDown at Testframework.CommonAction.CaptureScreen(String fileName) in CommonAction.cs: line 121 at Test.RegistrationTest.SnapshotOnFailure() in RegistrationTest.cs: line 590

最佳答案

线索确实在错误中。

Chrome 应该安装在运行测试或指向测试的系统上。

退一步,看文档:

https://code.google.com/p/selenium/wiki/ChromeDriver

此外,如果 Chrome 安装在特殊位置,您需要将 Selenium 指向它的位置。同样,这在文档中进行了解释。

在 C# 中:

DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
capabilities.SetCapability("chrome.binary", this.binaryLocation);

或:

ChromeOptions options = new ChromeOptions();
options.BinaryLocation = "pathtogooglechrome";
capabilities.SetCapability(ChromeOptions.Capability, options);

关于c# - 远程 Webdriver Chrome 抛出 "path to the driver executable"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15199545/

相关文章:

python - 如何使用 python 为远程 selenium webdriver 配置特殊代理设置?

python - 如何在 SmartTV 浏览器上使用 selenium

c# - 有没有办法在不统一使用 Update() 函数的情况下从按钮单击启动方法

c# - 选择列表中的项目时如何将属性值设置为 null

java - TestNG <test> 中的 WebDriver 实例共享

java - WebDriver PhantomJS 无法找到元素,但可以在 Firefox 上正常工作

python - Windows7 本地主机上的 Selenium Remote Webdriver 抛出空指针异常

c# - 如何重构看起来相同的方法调用?

c# - 使用 Hololens 进行图像识别

javascript - WebDriver Selenium : Javascript code coverage without server access