无法解析构造函数FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)

Nab*_*man 4 java selenium webdriver selenium-webdriver

有人可以帮我这段代码。当前它将在第4行上抱怨:webDriver =新的FirefoxDriver(ff_ep_profiles)说它无法解析构造函数。我需要加载扩展程序,因此我正在创建配置文件

FirefoxProfile ff_ep_profile = new FirefoxProfile(new File("C:\\Users\\admin\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\81uy033g.FirefoxEP"));
    FirefoxOptions option=new FirefoxOptions();
    option.setProfile(ff_ep_profile);
    webDriver = new FirefoxDriver(ff_ep_profile);
Run Code Online (Sandbox Code Playgroud)

Deb*_*anB 5

在使用Selenium v​​3.11.xGeckoDriver v0.20.0Firefox Quantum v59.0.2时,可以使用不同的选项来调用新的/现有的Firefox配置文件

如果您希望在每次执行测试时使用新的 Firefox配置文件,则可以使用以下代码块:

System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(new FirefoxProfile());
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");
Run Code Online (Sandbox Code Playgroud)

如果您正在寻找使用一个现有 的Firefox配置文件在您每次运行测试执行首先你必须创建一个Firefox的配置文件手动下面的说明在Windows上创建新的Firefox配置文件

现在,您有两种方法可以调用已创建的Firefox配置文件,如下所示:

  • 您可以使用FirefoxOptions类来调用现有的Firefox配置文件,并且可以使用以下代码块:

    System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile testprofile = profile.getProfile("debanjan");
    FirefoxOptions opt = new FirefoxOptions();
    opt.setProfile(testprofile);
    WebDriver driver =  new FirefoxDriver(opt);
    driver.get("https://www.google.com");
    
    Run Code Online (Sandbox Code Playgroud)
  • 您还可以使用DesiredCapabilities类设置现有的Firefox配置文件,然后在FirefoxOptions实例中合并,并且可以使用以下代码块:

    System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile testprofile = profile.getProfile("debanjan");
    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability(FirefoxDriver.PROFILE, testprofile);
    FirefoxOptions opt = new FirefoxOptions();
    opt.merge(dc);
    WebDriver driver =  new FirefoxDriver(opt);
    driver.get("https://www.google.com");
    
    Run Code Online (Sandbox Code Playgroud)