51Testing软件测试论坛

标题: selenium3.3+Firefox54(最新版) WebDriver报错? [打印本页]

作者: 悠悠小仙仙    时间: 2017-11-28 14:13
标题: selenium3.3+Firefox54(最新版) WebDriver报错?
初学者,配置好了一切,网上找了一些demo

代码如下:
  1. package Selenium_Java;

  2. import java.io.File;

  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.WebElement;
  6. import org.openqa.selenium.chrome.ChromeDriver;
  7. import org.openqa.selenium.firefox.FirefoxDriver;
  8. import org.openqa.selenium.ie.InternetExplorerDriver;

  9. public class test111 {

  10. public static void main(String[] args) {


  11. //System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
  12. WebDriver driver = new FirefoxDriver();//创建火狐

  13. driver.get("http://www.baidu.com");//打开百度
  14. driver.manage().window().maximize();//最大化
  15. WebElement  element = driver.findElement(By.id("kw"));
  16. element.sendKeys("HelloWorld");//输入值china
  17. driver.findElement(By.id("su")).click();

  18. System.out.println("asdasd");
  19. }

  20. }
复制代码
报错如下:

  1. 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
  2. at com.google.common.base.Preconditions.checkState(Preconditions.java:738)
  3. at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:111)
  4. at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:38)
  5. at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:112)
  6. at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:302)
  7. at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:233)
  8. at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
  9. at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:121)
  10. at Selenium_Java.test111.main(test111.java:22)
复制代码
报错那行是:WebDriver driver = new FirefoxDriver();//创建火狐

我看别人demo都是有上面那一段就打开了火狐浏览器
下面报错看不懂。。。求大神支援下。很不懂


作者: 悠悠小仙仙    时间: 2017-11-28 14:43
[attach]109482[/attach]
[attach]109481[/attach]
这行代码报错:driver = new FirefoxDriver();//创建火狐
这是为什么,但是我的火狐浏览器是打开了的

作者: 草帽路飞UU    时间: 2017-11-28 14:44

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





欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2