java selenium启动火狐浏览器报错: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
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在默认路径下;
2.直接用System.setProperty方法设置webdriver.firefox.bin的值
3.利用setCapability进行设置
4.用FirefoxBinary类和public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile)这个构造方法
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 {
- /**
- * @param args
- */
- 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/");
- }
- }
本文来自博客园,作者:热爱技术的小牛,转载请注明原文链接:https://www.cnblogs.com/my-blogs-for-everone/p/8026878.html