我正在尝试在Eclipse上运行简单的selenium webdriver案例,但它会抛出错误。
我的代码:
package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Demo {
public static void main(String[] args) {
String MyURL = "http://www.google.com";
WebDriver driver = new FirefoxDriver();
driver.get(MyURL);
//close Firefox
driver.close();
// exit the program explicitly
System.exit(0);
}
}
Following lines are errors.
Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'VW003419', ip: '10.68.30.32', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:74)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:60)
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:56)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
at automationFramework.Demo.main(Demo.java:16)
这也发生在Chrome上。我已将其安装在默认位置。
答案 0 :(得分:0)
请尝试打开下面的镀铬
// call the Chrome driver as below first
System.setProperty("webdriver.chrome.driver", "D:\\eclipseProject\\##\\src\\com\\##\\chromedriver_win32\\chromedriver.exe");
// path to chrome exe that you have downloaded form given url (below)
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.seleniumhq.com"); // link to your web-table web page
下载chrome exe
答案 1 :(得分:0)
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class First {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
// Create a new instance of the Firefox driver
System.setProperty("webdriver.chrome.driver", "D:\\Personal");
WebDriver driver = new ChromeDriver();
//Launch the Online Store Website
driver.get("http://www.store.demoqa.com");
// Print a Log In message to the screen
System.out.println("Successfully opened the website www.Store.Demoqa.com");
//Wait for 5 Sec
Thread.sleep(5);
// Close the driver
driver.quit();
}
}
异常日志:
Exception in thread "main" java.lang.IllegalStateException: The driver executable is a directory: D:\Personal
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:123)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:116)
at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
at First.main(First.java:12)`enter code here`
答案 2 :(得分:-1)
您需要指定chromedriver.exe而不仅仅是目录名称:
System.setProperty("webdriver.chrome.driver", "D:\\Personal");
应该是这样的:
System.setProperty("webdriver.chrome.driver", "D:\\Personal\\chromedriver.exe");