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

标签 java selenium selenium-webdriver webdriver

有人可以帮我处理这段代码吗?目前它会在第 4 行提示 : webDriver = new 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);

最佳答案

在使用 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 Profile 按照 Creating a new Firefox profile on Windows 处的说明手动操作.

现在您有 2 种方法来调用您创建的 Firefox 配置文件,如下所示:

  • 您可以使用 FirefoxOptions 类来调用现有的 Firefox Profile 并且可以使用以下代码块:

    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");
    

关于java - 无法解析构造函数 FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49683355/

相关文章:

java - 如何通过游标获取android中的Timestamp列值?

java - Java中如何确定集合中的类?

java - 如何使用 webdriver 在 Firefox 中处理下载 .xlsx 文件,其中窗口弹出默认为 'Open with' 单选按钮而不是 'Save file'

java - 无法运行 JAR - 使用 Java 进行 Spark Twitter Streaming

java - 如何只显示点击按钮的数据?

python - 如何使用 Selenium 向 ChromeDriver 提交 HTTP 身份验证(Flask BASIC Auth)

java - 如何使用 selenium 导航到同级 <p> 元素

linux - Selenium 无法在 Linux 上打开虚拟浏览器窗口

node.js - 检查是否找到任一元素

c# - 与列表中的Webdriver元素进行交互