2017-02-07 98 views
1
Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: LINUX Build info: version: 'unknown', revision: '1969d75', time: '2016-10-18 09:43:45 -0700' 
System info: host: 'skalia', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.19.0-25-generic', java.version: '1.8.0_111' 
Driver info: driver.version: FirefoxDriver 
at org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:75) 
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:60) 
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:56) 
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:127) 
at pack.SeleTest.main(SeleTest.java:10) 

這是我在運行selenium腳本期間得到的錯誤,它在Window PC上正常工作。我設置了所有的構建路徑。添加所有的硒罐。 幫我解決它。如何在Linux中設置Firefox的Firefox的二進制路徑?

回答

0

要麼 Firefox的二進制文件添加到PATH變量編程方式使用FirefoxDriver採取FirefoxBinary構造集,像這樣的:

FirefoxDriver(FirefoxBinary binary, FirefoxProfile profile); 

要找出路在火狐瀏覽器的二進制在Linux上,在shell中運行此命令:

which firefox 

如果這不顯示路徑或顯示錯誤消息,則Firefox未安裝在您的Linux系統上(如果它安裝在Windows PC上,那麼這就是它在那裏工作的原因)。

1

在Java語言:

如果您在默認位置安裝Firefox你只寫:

WebDriver driver = new FirefoxDriver(); 

對於其他位置,您可以編碼象下面這樣:

File browserAppPath = null; 
if (Platform.getCurrent().is(Platform.WINDOWS)) { 
    browserAppPath = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe"); 
    if (!browserAppPath.exists()) { 
     browserAppPath = new File("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); 
    } 
} else { 
    // Ubuntu 
    browserAppPath = new File("/usr/bin/firefox/firefox-bin"); 
} 
WebDriver driver = new FirefoxDriver(new FirefoxBinary(browserAppPath), new FirefoxProfile()); 
+0

感謝救我的一天:) –

相關問題