- package testselenium;
-
- import java.io.File;
- import java.util.concurrent.TimeUnit;
-
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.firefox.FirefoxProfile;
-
- public class OpenFirefox {
- public static void main(String[] args) throws InterruptedException{
-
- FirefoxProfile firefoxProfile =new FirefoxProfile(new File("D:\\Program Files\\Mozilla Firefox\\"));
-
- WebDriver driver=new FirefoxDriver(firefoxProfile);
-
- driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
-
- driver.get("http://www.baidu.com/");
-
- Thread.sleep(3000);
-
- driver.close();
- }
- }
错误: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的目录。
- System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe");
- WebDriver driver=new FirefoxDriver();
3、使用FirefoxBinary类
- File pathToFirefoxBinary =new File("D:\\Program Files\\Mozilla Firefox\\firefox.exe");
- FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary);
- WebDriver driver = new FirefoxDriver(firefoxbin,null);