打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
“Cannot find firefox binary in PATH. ”错误。

“Cannot find firefox binary in PATH. ”错误。

分类: selenium 31人阅读 评论(0) 收藏 举报

  1. package testselenium;  
  2.   
  3. import java.io.File;  
  4. import java.util.concurrent.TimeUnit;  
  5.   
  6. import org.openqa.selenium.WebDriver;  
  7. import org.openqa.selenium.firefox.FirefoxDriver;  
  8. import org.openqa.selenium.firefox.FirefoxProfile;  
  9.   
  10. public class OpenFirefox {  
  11.     public static void main(String[] args) throws InterruptedException{  
  12. //      设置本地firefox启动目录  
  13.         FirefoxProfile firefoxProfile =new FirefoxProfile(new File("D:\\Program Files\\Mozilla Firefox\\"));  
  14. //      定义firefox一个driver对象  
  15.         WebDriver driver=new FirefoxDriver(firefoxProfile);  
  16. //      设置默认的响应时间  
  17.         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);  
  18. //      打开访问地址  
  19.         driver.get("http://www.baidu.com/");  
  20. //      设置休眠时间  单位毫秒  
  21.         Thread.sleep(3000);  
  22. //      关闭浏览器  
  23.         driver.close();  
  24.     }  
  25. }  


错误:Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:08:56'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_06'
Driver info: driver.version: FirefoxDriver

原因:firefox安装不是默认目录。

解决:

1、firefox安装到默认目录

2、使用setProperty方法更改webdriver.firefox.bin中firefox的目录。

  1. System.setProperty("webdriver.firefox.bin""D:\\Program Files\\Mozilla Firefox\\firefox.exe");  
  2. WebDriver driver=new FirefoxDriver();  

3、使用FirefoxBinary类

  1. File pathToFirefoxBinary =new File("D:\\Program Files\\Mozilla Firefox\\firefox.exe");  
  2. FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary);  
  3. WebDriver driver = new FirefoxDriver(firefoxbin,null);//这里使用这个构造方法。  



本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
webdriver 启动firefox driver时,加载firebug的扩展
Selenium2(WebDriver)总结(一)
Selenium WebDriver 之 PageObjects 模式 by Example
Selenium2(webdirver)入门之环境搭建(Java版)
selenium+python自动化80-文件下载(不弹询问框)
火狐忽略下载弹框设置
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服