首页 文章

构造函数FirefoxDriver(FirefoxOptions)未定义

提问于
浏览
0

我正在使用Selenium 3.5.3,以下是我的代码 .

我试图在构造函数中使用Firefox选项
https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/firefox/FirefoxDriver.html#FirefoxDriver-org.openqa.selenium.firefox.FirefoxOptions-

FirefoxOptions options=new FirefoxOptions();
options.setProfile(profile);
driver =new FirefoxDriver(options);

我在实例化Firefox驱动程序时遇到错误:

构造函数FirefoxDriver(FirefoxOptions)未定义

我怎么解决这个问题?

Firefox版本55.0.3 64位Geckodriver v0.18.0

3 回答

  • 0

    试试这段代码:

    import java.io.File;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.firefox.FirefoxOptions;
    import org.openqa.selenium.firefox.FirefoxProfile;
    
    public class FirefoxOptionsDemo {
    
    public static void main(String[] args) {
    System.setProperty("webdriver.gecko.driver", "E:\\software and tools\\geckodriver.exe");
    FirefoxProfile profile =new FirefoxProfile(new File("C:\\Users\\sys\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\ejtrne37.QAProfile"));
    FirefoxOptions option=new FirefoxOptions();
    option.setProfile(profile);
    // Initialize Firefox driver
    WebDriver driver = new FirefoxDriver(option);
    //Maximize browser window
    driver.manage().window().maximize();
    //Go to URL which you want to navigate
    driver.get("http://www.google.com");
    //Set  timeout  for 5 seconds so that the page may load properly within that time
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    //close firefox browser
    driver.close();
    }
    }
    

    这是供您参考的图片:

    FirefoxOptions Constructor

  • 1

    问题是由于较旧的硒版本共存 . mvn clean install解决了这个问题 .

  • 2

    您的问题可能与不同原因有关 . 常见原因是你的firefox浏览器的 missaligned version 和/或 gecko driver and/or selenium library .

    我解决了这个问题 upgrading gecko驱动程序和selenium库到最新版本 .

    在我的情况下,mvn clean install没有解决问题

相关问题