selenium3.3+Firefox54(最新版) WebDriver报错?
初学者,配置好了一切,网上找了一些demo代码如下:
package Selenium_Java;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class test111 {
public static void main(String[] args) {
//System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();//创建火狐
driver.get("http://www.baidu.com");//打开百度
driver.manage().window().maximize();//最大化
WebElementelement = driver.findElement(By.id("kw"));
element.sendKeys("HelloWorld");//输入值china
driver.findElement(By.id("su")).click();
System.out.println("asdasd");
}
}报错如下:
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
at com.google.common.base.Preconditions.checkState(Preconditions.java:738)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:111)
at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:38)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:112)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:302)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:233)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:121)
at Selenium_Java.test111.main(test111.java:22)报错那行是:WebDriver driver = new FirefoxDriver();//创建火狐
我看别人demo都是有上面那一段就打开了火狐浏览器
下面报错看不懂。。。求大神支援下。很不懂
这行代码报错:driver = new FirefoxDriver();//创建火狐
这是为什么,但是我的火狐浏览器是打开了的
1.指定geckodriver的路径
System.setProperty("webdriver.gecko.driver", "D:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
2.如果还是报错,更换selenium的jar包,更换为selenium-server-standalone-3.4.0.jar;
我的火狐浏览器的版本是51
页:
[1]