小编典典

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

selenium

有人可以帮我这段代码。当前它将在第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);

阅读 410

收藏
2020-06-26

共1个答案

小编典典

在使用 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");

如果您正在寻找使用一个 现有 的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");
  • 您还可以使用 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");
2020-06-26