【发布时间】:2021-04-09 15:37:33
【问题描述】:
我目前正在尝试使用 Selenium 在 Linux 上自动执行一些浏览任务(我正在运行 Linux Mint 20)。但是,我遇到了障碍:我无法让它找到任何浏览器二进制文件。我尝试过使用 Firefox 和 Chromium(我想如果我可以加载 Chromium 二进制文件,我会接受),但它们都产生相同的结果,Selenium 说它找不到浏览器二进制文件。
这是我的代码:
package test1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class app
{
public static void main(String[] args)
{
System.setProperty("webdriver.firefox.driver", "/home/ann/bin/geckodriver");
WebDriver driver = new FirefoxDriver();
}
}
以下是运行代码后的结果:
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: '4.0.0-alpha-7', revision: 'de8579b6d5'
System info: host: 'ann-System-Product-Name', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-58-generic', java.version: '11.0.8'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:95)
at java.base/java.util.Optional.orElseGet(Optional.java:369)
at org.openqa.selenium.firefox.FirefoxOptions.getBinary(FirefoxOptions.java:199)
at org.openqa.selenium.firefox.GeckoDriverService$Builder.withOptions(GeckoDriverService.java:180)
at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:177)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:155)
at test1.app.main(app.java:10)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Firefox 已安装并可从终端执行:
ann@ann-System-Product-Name:~$ whereis firefox
firefox: /usr/bin/firefox /usr/lib/firefox /etc/firefox
Geckodriver 在我的$PATH 中,执行它会得到以下结果:
ann@ann-System-Product-Name:~$ geckodriver
1609693404322 geckodriver INFO Listening on 127.0.0.1:4444
【问题讨论】:
标签: java selenium google-chrome selenium-webdriver firefox