gpt4 book ai didi

linux - 如何在Linux中的selenium中设置Firefox的Firefox二进制路径?

转载 作者:行者123 更新时间:2023-12-03 09:56:20 27 4
gpt4 key购买 nike

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 上运行良好。我设置了所有的构建路径。添加所有 Selenium jar 。帮我解决一下。

最佳答案

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());

关于linux - 如何在Linux中的selenium中设置Firefox的Firefox二进制路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42094021/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com