火狐浏览器无法启动java_selenium不能启动firefox浏览器,怎么办?

Java代码如下(环境:eclipse Oxygen+JDK1.8+selenium3.8.1+Junit5+firefox48.0.2)

1.报错信息如下

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

1 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 fromhttps://github.com/mozilla/geckodriver/releases

2 at com.google.common.base.Preconditions.checkState(Preconditions.java:754)3 at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)4 at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)5 at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:141)6 at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)7 at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:158)8 at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)9 at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)…………

部分源码如下:

@Testpublic void setUp() throwsException {try{

driver= newFirefoxDriver();

driver.get("https://www.baidu.com/");

System.out.print(driver.getTitle());

driver.quit();

}catch(Exception e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}

2.解决方法如下:

根据报错提示意为,缺少驱动。

(1)根据提示链接:https://github.com/mozilla/geckodriver/releases

下载最新驱动

20180111010527474375.png

(2)解压下载文件,把解压后的文件放入firefox.exe的同目录,默认为 C:\Program Files (x86)\Mozilla Firefox

(3)在源码中的加入

System.setProperty("webdriver.firefox.marionette",

"C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe");

如下:

1 @Test2 public void setUp() throwsException {3

4 try{5 System.setProperty("webdriver.firefox.marionette",

6 "C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe");

7 driver = newFirefoxDriver();8 driver.get("https://www.baidu.com/");9 System.out.print(driver.getTitle());10 driver.quit();11 } catch(Exception e) {12 //TODO Auto-generated catch block

13 e.printStackTrace();14 }15 }

3.ok,解决了!(其他问题待补充)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值