2013-03-04 31 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

相關問題