2013-08-16 30 views
22

我想node.js selenium web driver example設置...錯誤:在驅動程序可執行文件的路徑必須由webdriver.chrome.driver系統屬性

var webdriver = require('selenium-webdriver'); 

var driver = new webdriver.Builder(). 
    usingServer('http://localhost:4444/wd/hub'). 
    withCapabilities(webdriver.Capabilities.chrome()). 
    build(); 

driver.get('http://www.google.com'); 
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver'); 
driver.findElement(webdriver.By.name('btnG')).click(); 
driver.wait(function() { 
return driver.getTitle().then(function(title) { 
    return title === 'webdriver - Google Search'; 
}); 
}, 1000); 

driver.quit(); 

...但遇到錯誤

promise.js:1542 
     throw error; 
      ^
UnknownError: 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 
    at new bot.Error (/Users/maks/Dropbox/nodeApps/orgi/node_modules/selenium-webdriver/lib/atoms/error.js:109:18) 

guessed設置PATH變量:

$ cat .bashrc 

export PATH=$PATH:/usr/local/git/bin/ 
export PATH=$PATH:~/bin 
export PATH=$PATH:~/Dropbox/chromedriver 

,並重新啓動控制檯,但得到了同樣的錯誤。

+0

我不得不使用Firefox來使用量角器在Linux上進行端到端測試。 – Droogans

回答

42

here使用硒的服務器standalone- *的.jar,你可以像這樣啓動時,它傳遞webdriver.chrome.driver屬性:

java -jar selenium-server-standalone-2.35.0.jar -Dwebdriver.chrome.driver="D:\dev\chromedriver.exe" 

這消除了錯誤; Java命令行選項-Dproperty=value按預期設置系統屬性值。

+0

你不需要逃避那些反斜槓嗎? – kajacx

+1

@kajacx:上面的語法對於「vanilla」命令行啓動是正確的 –

+0

我知道這是舊帖子,但從Behat 2遷移到Behat 3後,這個解決方案對我來說已經非常有用,後者抱怨着chromedriver。 +1 – BentCoder

-2

您可以使用下面的代碼來設置路徑在代碼中引號內提到

System.setProperty("webdriver.chrome.driver", "your_path"); 

路徑。

+4

無法使用nodejs工作。 – CodeGuru

2

如果你不想使用硒服務器只是想直接使用chromedriver,像這樣將工作:

var chrome = require('selenium-webdriver/chrome'); 
var service = new chrome.ServiceBuilder(__dirname + '/node_modules/.bin/chromedriver').build(); 
var driver = new chrome.createDriver(capabilities, service); 

這不是很好的記錄,我不得不閒逛源代碼一點。

+0

如何在使用'chrome.Options()'的同時仍然可以使用它? –

0

我發現的最簡單的解決方案是使chromedriver文件可執行。

錯誤:

**-rw-rw-r--** 1 user user 5560736 Jul 31 00:56 chromedriver 

正確:

**-rwxrwxr-x** 1 user user 58204704 Aug 14 08:18 phantomjs 

一旦chromedriver匹配phantomjs它竄出來生活

5

萬一有人收到此錯誤:

Exception in thread "main" com.beust.jcommander.ParameterException: Unknown option: -Dwebdrive

thread可能幫助:

使用參數之前jar文件

java [-options] -jar jarfile [args...] (to execute a jar file) 

所以,你的命令應該是:

java -jar -Dwebdriver.chrome.driver="D:\dev\chromedriver.exe" selenium-server-standalone-2.35.0.jar 

希望它可以幫助別人的未來。

相關問題