【问题标题】:Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)无法解析构造函数 FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)
【发布时间】:2018-09-15 22:11:58
【问题描述】:

有人可以帮我处理这段代码吗?目前它会在第 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);

【问题讨论】:

  • WebDriver 驱动在哪里?也许您正在尝试创建一个变量 webDriver,而不是 WebDriver driver=new FirefoxDriver(ff_ep_profile);

标签: java selenium selenium-webdriver webdriver


【解决方案1】:

在使用 Selenium v​​3.11.x、GeckoDriver v0.20.0 和 Firefox 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 配置文件 按照Creating a new Firefox profile on Windows 的说明手动操作。

现在您有 2 种方法来调用您创建的 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");
    

【讨论】:

  • 在我使用远程 webDriver 时如何加载配置文件的任何建议......基本上配置文件的目的是让我可以加载扩展。
  • 当您通过 _DesiredCapabilities 类加载 FirefoxProfile _ 时,您始终可以通过它。
猜你喜欢
  • 1970-01-01
  • 2015-05-29
  • 1970-01-01
  • 2015-05-05
  • 2017-02-28
  • 2016-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多