我正在尝试用Java获取webdriver实例。我在后台运行了selenium。
org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
Command duration or timeout: 121 milliseconds
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:16:47'
System info: host: 'ARMac.home', ip: '192.168.1.5', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.8.0_11'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
我的代码看起来像这样
System.setProperty("webdriver.chrome.driver", System.getProperty("user.home") + "/chromedriver");
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setJavascriptEnabled(true);
desiredCapabilities.setCapability("takesScreenshot", true);
String link = "http://www.google.com";
WebDriver driver = new RemoteWebDriver(new URL(
"http://127.0.0.1:4444/wd/hub"), desiredCapabilities);
我运行Selenium的方式是
java -jar selenium-server-standalone-2.46.0.jar -timeout=20
答案 0 :(得分:1)
将chrome webdriver位置添加到java调用中:
java -jar selenium-server-standalone-2.46.0.jar -timeout = 20 -Dwebdriver.chrome.driver = C:\ path-to \ chromedriver.exe
如果您决定使用IE驱动程序,则需要添加它,例如:
-Dwebdriver.ie.driver = C:\路径到\ IEDriverServer.exe