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

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在默认路径下;
OS Expected Location of Firefox
Linux firefox (found using “which”)
Mac /Applications/Firefox.app/Contents/MacOS/firefox
Windows %PROGRAMFILES%\Mozilla Firefox\firefox.exe
2.直接用System.setProperty方法设置webdriver.firefox.bin的值
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进行设置
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) {
// TODO Auto-generated method stub
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)这个构造方法
package selenium.test.googleSearch;

import java.io.File;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.*;
public class BaiduFirefoxDriver {

public static void main(String[] args) {
// TODO Auto-generated method stub
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/");
}

}
原文链接:http://aitawo.com/2013/02/16/%e4%bd%bf%e7%94%a8firefoxdriver%e6%97%b6%e6%8a%a5%e9%94%99make-sure-firefox-is-installed%e9%97%ae%e9%a2%98/ | @wo 高凯的博
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值