1

得到错误:

配置失败:@BeforeMethod setUp org.openqa.selenium.WebDriverException:驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统属性设置;有关详细信息,请参阅 http://code.google.com/p/selenium/wiki/ChromeDriver。最新版本可从 http://chromedriver.storage.googleapis.com/index.html下载

我的代码:

capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
String strChromePath = System.getProperty("user.dir")
    + "\\webdrivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", strChromePath);
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
        capability);

在上面的代码 chromedriver 中,它自己没有被调用。

然后我尝试了代码:

ChromeDriverService chromeService = new ChromeDriverService.Builder()
            .usingDriverExecutable(new File("webdrivers/chromedriver.exe"))
            .usingAnyFreePort().build();
chromeService.start();
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
        capability);

在执行上述代码时,可执行文件会启动,但不会调用 chrome。它抛出相同的错误。代码在 Firefox 上运行良好。请问有什么帮助吗?

4

2 回答 2

0

试试下面:

    WebDriver driver;

    System.setProperty("webdriver.chrome.driver", "properties/chromedriver.exe");

    driver = new ChromeDriver();

    driver.get("www.google.com");

将 chrome 驱动程序放在属性文件夹中。

于 2014-11-19T09:35:52.497 回答
0

根据您的系统(32 位/64 位)从此处下载相关的 Chrome 驱动程序。尝试先设置 ChromeDriver 的属性,如下所示:

File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());

然后使用此代码:-

DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),capability);

如果不需要使用“RemoteWebDriver”,您可以使用以下代码:

File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
于 2014-11-19T09:39:52.133 回答