node.js 错误:驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18272468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: The path to the driver executable must be set by the webdriver.chrome.driver system property
提问by Maxim Yefremov
I am trying node.js selenium web driver example...
我正在尝试node.js selenium web 驱动程序示例...
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();
... but got error
...但有错误
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)
I guessedto set PATH variable:
我猜想设置 PATH 变量:
$ cat .bashrc
export PATH=$PATH:/usr/local/git/bin/
export PATH=$PATH:~/bin
export PATH=$PATH:~/Dropbox/chromedriver
And restart console, but got the same error.
并重新启动控制台,但得到了同样的错误。
回答by o.v.
Using selenium-server-standalone-*.jar from here, you can pass webdriver.chrome.driverproperty when launching it like so:
从这里使用 selenium-server-standalone- *.jar ,您可以在启动它时传递属性,如下所示:webdriver.chrome.driver
java -jar selenium-server-standalone-2.35.0.jar -Dwebdriver.chrome.driver="D:\dev\chromedriver.exe"
This eliminates the error; Java command line option -Dproperty=valuesets a system property value as expected.
这消除了错误;Java 命令行选项-Dproperty=value按预期设置系统属性值。
回答by ProllyGeek
Just in case some one getting this error :
以防万一有人收到此错误:
Exception in thread "main" com.beust.jcommander.ParameterException: Unknown option: -Dwebdrive
线程“main”com.beust.jcommander.ParameterException 中的异常:未知选项:-Dwebdrive
this threadmight help :
这个线程可能有帮助:
Use Parameters before jar file
在 jar 文件之前使用参数
java [-options] -jar jarfile [args...] (to execute a jar file)
So your command should be:
所以你的命令应该是:
java -jar -Dwebdriver.chrome.driver="D:\dev\chromedriver.exe" selenium-server-standalone-2.35.0.jar
Hope it helps someone in future.
希望它可以帮助将来的人。
回答by timlesallen
If you don't want to use the selenium server but just want to use the chromedriver directly, something like this will work:
如果您不想使用 selenium 服务器而只想直接使用 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);
It's not very well documented, I had to poke around the source code a bit.
它没有很好的文档记录,我不得不稍微浏览一下源代码。
回答by Paul Lockwood
The simplest solution I found is to make the chromedriver file executable.
我找到的最简单的解决方案是使 chromedriver 文件可执行。
Incorrect:
不正确:
**-rw-rw-r--** 1 user user 5560736 Jul 31 00:56 chromedriver
Correct:
正确的:
**-rwxrwxr-x** 1 user user 58204704 Aug 14 08:18 phantomjs
Once chromedriver matched phantomjs it sprang to life
一旦 chromedriver 与 phantomjs 匹配,它就会活跃起来
回答by user2525437
You can use the following code to set path in your code
您可以使用以下代码在代码中设置路径
System.setProperty("webdriver.chrome.driver", "your_path");
Path to be mentioned within quotes.
要在引号中提及的路径。

