完整代码:
public class StartBrower {
public static void main(String[] args) {
WebDriver dr =new ChromeDriver();
}
}
1、报错内容
Exception in thread "main" java.lang.IllegalStateException: 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.htmlat com.google.common.base.Preconditions.checkState(Preconditions.java:197)at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:290)at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:116)
at com.ds.www.dan.StartBrower.main(StartBrower.java:9)
Process finished with exit code 1
2、问题分析:
无驱动;
3、解决办法;
下载chromedriver.exe,下载网址:https://sites.google.com/a/chromium.org/chromedriver/downloads
4、更新代码:
public class StartBrower {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\myPlace\\chromedriver.exe");
WebDriver dr =new ChromeDriver();
dr.get("http://www.baidu.com");
}
}
5、测试结果: