分享

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

 yzqwqp 2013-10-16

“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);//这里使用这个构造方法。  



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多