我正在尝试在我的项目中导入 Firefox,但它根本没有导入,即使我也降级了 selenium 版本。我正在使用以下 selenium maven 依赖项:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
每当我尝试导入
FireFoxOptions
。它显示红色文字,我需要知道,如果我犯了任何错误。
第一:你能和webdrivemanager一起工作吗?它将帮助您使用 firefox 配置 selenium。
第二:要使用 Firefox 选项(例如:最大化你的窗口)使用这个例子:
// Create an instance of FirefoxOptions
FirefoxOptions options = new FirefoxOptions();
// Maximize the Firefox window
options.addArguments("--start-maximized");
// Create an instance of Firefox with the options applied
WebDriver driver = new FirefoxDriver(options);
希望对你有帮助!
Selenium maven 依赖是完美的。
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
而不是进口
FireFoxOptions
你应该进口FirefoxOptions
。演示:
代码块:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
public class genericTestFirefox {
public static void main(String[] args) {
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
}
}
浏览器快照: