2013-03-04 56 views
4

嗨当​​我使用下面的代码远程webdriver的镀铬抛出一个“路径驱动程序可执行文件”的错误

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

我得到follwing错误

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(响应错误响应) 在OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串driverCommandToExecute,Dictionary`2参数) 在OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor ,ICapabilities desiredCapabilities) at Browser.cs中的Testframework.Browser.RemoteGoto(String browser,String url):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):Line 50 --TearDown 在Testframework.CommonAction.CaptureScreen(字符串文件名)在CommonAction.cs:线121 在Test.RegistrationTest.SnapshotOnFailure()在RegistrationTest.cs:线590

回答

4

线索真的是在错误。

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

退一步,看看文档:

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

另外,如果安装在特殊的地方浏览器,你需要它的位置指向硒。再次,这是在文档中解释。

在C#:

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

或:

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

嗨,我能够找到只有java的例子,你能告诉我如何设置在C#webdriver远程铬的路径,因为我无法找到在C#q – 2013-03-04 11:35:23

+0

编辑向您展示。 – Arran 2013-03-04 12:30:18

+0

谢谢你,这是我设置的路径options.BinaryLocation = @“.. \ RequiredFiles \ chromedriver_win_26.0.1383.0 \ chromedriver.exe”;我收到以下错误“驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置” – 2013-03-04 13:03:14

4

改变代码,而不是你可以有一轮别的办法。
下载chrome驱动程序并设置指向chromedriver.exe所在目录的环境变量PATH环境变量。

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

+0

谢谢你有没有其他方式设置为环境变量。我还发现这个解决方案在启动控制台时设置了chromedriver路径(java -Dwebdriver.chrome.driver = C:\ example \ chromedriver.exe -jar selenium-server-standalone-2.31.0.jar)。我希望尽可能避免使用此解决方案,并在代码中设置路径,以便代码保持可移植性。 – 2013-03-05 08:13:10

+0

@AnandS要将代码保持为便携式,最好如果我们没有硬编码驱动程序的位置。我更喜欢设置路径,因为开发的测试可以移植到任何机器上,只需设置PATH – 2013-03-05 09:03:30

+0

谢谢你,我很好奇为什么当我使用这个System.Environment.SetEnvironmentVariable(“webdriver.chrome .driver“,@”/ path/to/w here/you/ve/put/chromedriver.exe“)chromedriver.exe没有设置环境变量 – 2013-03-05 10:09:51

相关问题