gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 02:36:26 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com