远程Webdriver Chrome抛出一个“驱动程序可执行路径”.错误

本文关键字:驱动程序 一个 可执行 路径 错误 Chrome Webdriver 远程 | 更新日期: 2023-09-27 18:02:10

嗨,当我使用以下代码

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

我得到以下错误

系统。InvalidOperationException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;欲了解更多信息,请访问http://code.google.com/p/selenium/wiki/ChromeDriver。最新版本可从http://code.google.com/p/chromedriver/downloads/list下载TearDown:系统。NullReferenceException:对象引用没有设置为对象的实例。在OpenQA.Selenium.Remote.RemoteWebDriver。UnpackAndThrowOnError(响应errorResponse)在OpenQA.Selenium.Remote.RemoteWebDriver。执行(字符串driverCommandToExecute,字典' 2个参数)在OpenQA.Selenium.Remote.RemoteWebDriver . .(icommandexexecutor命令,ICapabilities desiredCapabilities)在Testframework.Browser。浏览器.cs中的RemoteGoto(字符串浏览器,字符串url):第86行在Testframework.CommonAction。CommonAction.cs中的RemoteBrowser(字符串浏览器):第70行在Test.RegistrationTest。在RegistrationTest.cs:第50行InvalidRegistrationTest(字符串浏览器,字符串用户名,字符串密码,字符串确认密码,字符串securityQuestion,字符串securityAnswer,字符串errorMessageText,字符串firstname,字符串lastname——拆卸在Testframework.CommonAction。CaptureScreen(字符串文件名)在CommonAction.cs:第121行在RegistrationTest.cs: line 590

远程Webdriver Chrome抛出一个“驱动程序可执行路径”.错误

真正的线索在错误中。

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

您可以采用其他方法来代替更改代码。
下载chrome驱动程序,将 PATH 环境变量指向chromedriver.exe所在的目录。

重新启动IDE/Command控制台并运行测试。它的工作原理!