報如下錯誤
Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: XP
Build info: version: '2.18.0', revision: '15704', time: '2012-01-27 17:37:17'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_23'
?
看這個報錯應該是firefox安裝路徑不是默認路徑。
解決方法:方法1、最簡單的重新安裝firefox到默認路徑。哈哈
方法2、直接用System.setPropert方法設置webdriver.firefox.bin的值,如
System.setProperty("webdriver.firefox.bin","D:\\Program Files\\Mozilla Firefox\\firefox.exe");
方法3、?用FirefoxBinary類和public FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile)這個構造方法,直接上代碼
File pathToFirefoxBinary = new File("D:\\Program Files\\Mozilla Firefox\\firefox.exe");
FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary);
WebDriver driver = new FirefoxDriver(firefoxbin,null);//這裏使用這個構造方法。
應該還可以在環境變量裏面設置firefox的路徑也可以,有愛好的可以試一下。