码迷,mamicode.com
首页 > 其他好文 > 详细

selenium不能启动firefox浏览器,怎么办?

时间:2017-12-11 16:09:57      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:toe   http   images   row   lte   generated   loaded   rac   common   

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 from https://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.<init>(FirefoxDriver.java:120)
 9     at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:98)
…………

部分源码如下:

      @Test
      public void setUp() throws Exception {
          
        try {

            driver = new FirefoxDriver();
            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

下载最新驱动

技术分享图片

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

(3)在源码中的加入

System.setProperty("webdriver.firefox.marionette",
                     "C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe");
如下:
 1       @Test
 2       public void setUp() throws Exception {
 3           
 4         try {
 5             System.setProperty("webdriver.firefox.marionette",
 6                     "C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe");
 7             driver = new FirefoxDriver();
 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,解决了!(其他问题待补充)

 

selenium不能启动firefox浏览器,怎么办?

标签:toe   http   images   row   lte   generated   loaded   rac   common   

原文地址:http://www.cnblogs.com/zhangyating/p/8023089.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!