Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z'

解决方法:

package my_automation;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver; public class open_browser_01 { public static void main(String[] args) throws InterruptedException {
// E:\Program Files (x86)\Mozilla Firefox
//System.setProperty("webdriver.gecko.driver", "E:\\webdriver\\geckodriver.exe");
System.setProperty("webdriver.firefox.bin", "E:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.baidu.com");
driver.manage().window().maximize();
Thread.sleep(5000);
driver.quit(); } }
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的值

  1. package selenium.test.googleSearch;
  2. import org.openqa.selenium.WebDriver;
  3. import org.openqa.selenium.firefox.*;
  4. public class BaiduFirefoxDriver {
  5. /**
  6. * @param args
  7. */
  8. public static void main(String[] args) {
  9. // TODO Auto-generated method stub
  10. System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe");
  11. WebDriver driver=new FirefoxDriver();
  12. driver.get("http://www.baidu.com/");
  13. }
  14. }

3.利用setCapability进行设置

  1. package selenium.test.googleSearch;
  2. import org.openqa.selenium.WebDriver;
  3. import org.openqa.selenium.firefox.*;
  4. import org.openqa.selenium.remote.DesiredCapabilities;
  5. public class BaiduFirefoxDriver {
  6. /**
  7. * @param args
  8. */
  9. public static void main(String[] args) {
  10. // TODO Auto-generated method stub
  11. DesiredCapabilities capability=DesiredCapabilities.firefox();
  12. capability.setCapability("firefox_binary",
  13. "D:\\Program Files\\Mozilla Firefox\\firefox.exe");
  14. WebDriver driver = new FirefoxDriver(capability);
  15. driver.get("http://www.baidu.com/");
  16. }
  17. }

4.用FirefoxBinary类和public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile)这个构造方法

  1. package selenium.test.googleSearch;
  2. import java.io.File;
  3. import org.openqa.selenium.WebDriver;
  4. import org.openqa.selenium.firefox.*;
  5. public class BaiduFirefoxDriver {
  6. /**
  7. * @param args
  8. */
  9. public static void main(String[] args) {
  10. // TODO Auto-generated method stub
  11. File pathToFirefoxBinary = new File("D:\\Program Files\\Mozilla Firefox\\firefox.exe");
  12. FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary);
  13. WebDriver driver = new FirefoxDriver(firefoxbin,null);
  14. driver.get("http://www.baidu.com/");
  15. }
  16. }
 
 

最新文章

  1. Service Broker应用(1):简介、同server不同DB间的数据传输
  2. mingW与cygwin
  3. Win8驱动测试模式
  4. 被投资人“送”入看守所 z
  5. js正则表达式验证账号手机号电话邮箱
  6. Project Euler 96:Su Doku 数独
  7. error MSB6006: “CL.exe”已退出
  8. GWT(Google Web Tookit) Eclipse Plugin的zip下载地址(同时提供GWT Designer下载地址)
  9. 使用C#对MongoDB中的数据进行查询,改动等操作
  10. Decoding BASE64 in ABAP
  11. git团队合作开发流程
  12. hive数据类型及其数据转换
  13. SVN---搭建幸福之家
  14. LeetCode 705 Design HashSet 解题报告
  15. CoAP 协议解析说明(转)
  16. java代码示例(5)
  17. [转] 基于NodeJS的前后端分离的思考与实践(五)多终端适配
  18. SpringMVC统一转换null值为空字符串的方法 !
  19. CountUp.js用法 让数字动起来的插件
  20. HttpClient-----待补充

热门文章

  1. 【第四课】kaggle案例分析四
  2. 安装低版本django1.11出错
  3. vue上传阿里云图片组件
  4. 匈牙利算法求最大匹配(HDU-4185 Oil Skimming)
  5. Huawei-R&S-网络工程师实验笔记20190608-VLAN划分基础(基于端口、MAC地址、子网地址、协议)
  6. Selenium的安装和简单实用——PhantomJS安装
  7. 【 Codeforces Global Round 1 B】Tape
  8. 【codeforces 508C】Anya and Ghosts
  9. Java基础学习总结(36)——Java注释模板
  10. nyoj_49_开心的小明_201403161133