无法解析构造函数 FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile) [英] Cannot resolve constructor FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)
问题描述
有人可以帮我处理这段代码吗?目前它会在第 4 行抱怨: webDriver = 新的 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 v3.11.x、GeckoDriver v0.20.0 和 FirefoxQuantum 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 Profile,您可以使用以下代码块:
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 配置文件按照在 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.
现在您有两种方法可以调用您创建的 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 配置文件,然后在 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屋!