使用FirefoxDriver时报错Make sure firefox is installed问题

上一篇 / 下一篇  2013-06-24 15:12:38 / 个人分类:selenium

FirefoxDriver调用firefox浏览器的安装路径应为C盘的默认目录下,若firefox安装在其他目录下执行时会报错:
Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: XP
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_10'

这是因为找不到firefox的原因。
解决办法:

1.重新安装firefox在默认路径下;
OSExpected Location of Firefox
Linuxfirefox (found using "which")
Mac/Applications/Firefox.app/Contents/MacOS/firefox
Windows%PROGRAMFILES%\Mozilla Firefox\firefox.exe

2.直接用System.setProperty方法设置webdriver.firefox.bin的值
Java代码
  • package selenium.test.googleSearch;
  • import org.openqa.selenium.WebDriver;
  • import org.openqa.selenium.firefox.*;
  • public class BaiduFirefoxDriver {
  • /**
  • * @param args
  • */
  • public static void main(String[] args) {
  • // TODO Auto-generated method stub
  • System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe");
  • WebDriver driver=new FirefoxDriver();
  • driver.get("http://www.baidu.com/");
  • }
  • }

3.利用setCapability进行设置
Java代码
  • package selenium.test.googleSearch;
  • import org.openqa.selenium.WebDriver;
  • import org.openqa.selenium.firefox.*;
  • import org.openqa.selenium.remote.DesiredCapabilities;
  • public class BaiduFirefoxDriver {
  • /**
  • * @param args
  • */
  • public static void main(String[] args) {
  • DesiredCapabilities capability=DesiredCapabilities.firefox();
  • capability.setCapability("firefox_binary",
  • "D:\\Program Files\\Mozilla Firefox\\firefox.exe");
  • WebDriver driver = new FirefoxDriver(capability);
  • driver.get("http://www.baidu.com/");
  • }
  • }

4.用FirefoxBinary类和public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile)这个构造方法
Java代码
  • package selenium.test.googleSearch;
  • import java.io.File;
  • import org.openqa.selenium.WebDriver;
  • import org.openqa.selenium.firefox.*;
  • public class BaiduFirefoxDriver {
  • /**
  • * @param args
  • */
  • public static void main(String[] args) {
  • File pathToFirefoxBinary = new File("D:\\Program Files\\Mozilla Firefox\\firefox.exe");
  • FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary);
  • WebDriver driver = new FirefoxDriver(firefoxbin,null);
  • driver.get("http://www.baidu.com/");
  • }
  • }


TAG:

 

评分:0

我来说两句

日历

« 2024-04-22  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 15101
  • 日志数: 12
  • 建立时间: 2012-06-27
  • 更新时间: 2013-07-26

RSS订阅

Open Toolbar