Selenium Chrome webdriver 异常

Selenium Chrome webdriver exception

我正在尝试获取 Java 中的 webdriver 实例。我在后台有 运行 硒。

    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

将 chrome 网络驱动程序位置添加到您的 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:\path-to\IEDriverServer.exe