嗨,当我使用下面的代码时
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/