Remote Webdriver Chrome throws a “path to the driver executable” error

时光总嘲笑我的痴心妄想 提交于 2020-01-11 09:08:23

问题


Hi when i use the following code

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

I get the follwing error

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


回答1:


The clue really is in the error.

Chrome should be installed on the system where the tests are either running on or being pointed to.

Take a step back, look at the documentation:

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

Also, if Chrome is installed in a peculiar place, you'll need to point Selenium to it's location. Again, this is explained in the documentation.

In C#:

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

or:

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



回答2:


Instead of changing the code you can have other way round.
Download the chrome driver and set the PATH environment variable pointing to the directory where the chromedriver.exe is present.

Restart your IDE / Command console and run the tests. It works!!!



来源:https://stackoverflow.com/questions/15199545/remote-webdriver-chrome-throws-a-path-to-the-driver-executable-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!