无法在 Selenium Java 中导入 FirefoxOptions

问题描述 投票:0回答:2

我正在尝试在我的项目中导入 Firefox,但它根本没有导入,即使我也降级了 selenium 版本。我正在使用以下 selenium maven 依赖项:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.4.0</version>
</dependency>

每当我尝试导入

FireFoxOptions
。它显示红色文字,我需要知道,如果我犯了任何错误。

java maven selenium-webdriver firefox geckodriver
2个回答
0
投票

第一:你能和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);

希望对你有帮助!


0
投票

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/");
      }
    }
    
  • 浏览器快照:

Firefox

© www.soinside.com 2019 - 2024. All rights reserved.