4

嗨,当我使用以下代码时

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

我收到以下错误

System.InvalidOperationException :驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置;有关详细信息,请参阅http://code.google.com/p/selenium/wiki/ChromeDriver。最新版本可以从http://code.google.com/p/chromedriver/downloads/list下载 TearDown : System.NullReferenceException : 对象引用未设置为对象的实例。在 OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) 在 OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 参数) 在 OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities ) 在 Browser.cs 中的 Testframework.Browser.RemoteGoto(String browser, String url) 处:CommonAction.cs 中 Testframework.CommonAction.RemoteBrowser(String browser) 处的第 86 行:Test.RegistrationTest.InvalidRegistrationTest(String browser, String username 处的第 70 行, 字符串密码, 字符串confirmPassword, 字符串securityQuestion, 字符串securityAnswer, 字符串errorMessageText, 字符串firstname,

4

2 回答 2

4

除了更改代码,您还可以采用其他方式。
下载 chrome 驱动程序并将PATH环境变量设置为指向 chromedriver.exe 所在的目录。

重新启动 IDE / 命令控制台并运行测试。有用!!!

于 2013-03-05T04:08:26.690 回答
4

线索确实在错误中。

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);
于 2013-03-04T10:39:23.857 回答