下面的错误,我很困惑,我尝试了不同的方式,我的操作系统是Mac。
current dir = /Users/rafa/eclipse-workspace/FirstSelenium_2
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: /Users/rafa/eclipse-workspace/FirstSelenium_2//Users/rafa/eclipse-workspace/FirstSelenium_2/src/chromedriver
at com.google.common.base.Preconditions.checkState(Preconditions.java:585)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:146)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:141)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at Test2.main(Test2.java:14)
的代码。
public static void main(String[] args) {
String dir = System.getProperty("user.dir");
System.out.println("current dir = " + dir);
//to open browser
System.setProperty("webdriver.chrome.driver","/Users/rafa/eclipse-workspace/FirstSelenium_2/src/chromedriver");
WebDriver d=new ChromeDriver();
String actualurl="https://www.mycontactform.com";
//open url
d.get(actualurl);
//printing the title of page
String title=d.getTitle();
System.out.println(title);
//printing the actual url
System.out.println("actual url: "+actualurl);
//printing the current url
System.out.println("current url: "+d.getCurrentUrl());
//maximize the window
d.manage().window().maximize();
}
我把驱动程序放在目录里,但还是出现了这个错误。
替换为
System.setProperty("webdriver.chrome.driver","/Users/rafa/eclipse-workspace/FirstSelenium_2/src/chromedriver");
替换为:
System.setProperty("webdriver.chrome.driver","/src/chromedriver");