无法解析构造函数FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile) [英] Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)

查看:164
本文介绍了无法解析构造函数FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我解决这段代码。目前它会在第4行b
上投诉:webDriver = new FirefoxDriver(ff_ep_profiles)
说它无法解析构造函数。我需要加载我的扩展,因此我正在创建一个配置文件

Can someone help me with this piece of code. Currently it will complain on line #4 : webDriver = new FirefoxDriver(ff_ep_profiles) saying it cannot resolve constructor. I need to load my extensions hence I am creating a profile

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时。 x GeckoDriver v0.20.0 Firefox Quantum v59.0.2 有不同的选项来调用新的/现有的 Firefox配置文件

While working with Selenium v3.11.x, GeckoDriver v0.20.0 and Firefox Quantum v59.0.2 there are different option to invoke a new/existing Firefox Profile

如果您希望在每次运行测试执行时使用 Firefox配置文件

If you are looking to use a new Firefox Profile on every run of your Test Execution you can use the following code block :

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 Profile 在每次运行测试执行时,首先必须按照 Firefox配置文件。 org / Creating_a_new_Firefox_profile_on_Windowsrel =nofollow noreferrer> 在Windows上创建新的Firefox配置文件

If you are looking to use an existing Firefox Profile on every run of your Test Execution first you have to create a Firefox Profile manually following the instructions at Creating a new Firefox profile on Windows.

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

Now you have 2 ways to invoke the Firefox Profile you have created as follows :


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

  • You can use the FirefoxOptions class to invoke the existing Firefox Profile and you can use the following code block :

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 Profile 以及稍后在 FirefoxOptions 的实例中合并,您可以使用以下代码块:

  • You can also use the DesiredCapabilities class to set the existing Firefox Profile and later merge within an instance of FirefoxOptions and you can use the following code block :

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


  • 这篇关于无法解析构造函数FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆