如何通过Java使用Selenium将功能和选项传递给Firefoxdriver

我有这个:

System.setProperty("webdriver.gecko.driver", "gecko/linux/geckodriver");

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference("network.proxy.no_proxies_on", "localhost");

profile.setPreference("javascript.enabled", true);

DesiredCapabilities capabilities = DesiredCapabilities.firefox();

capabilities.setCapability("marionette", true);

capabilities.setCapability(FirefoxDriver.PROFILE, profile);

FirefoxOptions options = new FirefoxOptions();

options.setLogLevel(Level.FINEST);

options.addPreference("browser.link.open_newwindow", 3);

options.addPreference("browser.link.open_newwindow.restriction", 0);

现在我有两个不同的构造函数:

WebDriver driver = new FirefoxDriver(capabilities);

WebDriver driver = new FirefoxDriver(options);

如何将它们(功能和选项)都传递给driver?顺便说一句,IDE告诉我FirefoxDriver(capabilities)不推荐使用。

回答:

你快到了 您需要使用的方法

类的合并 DesiredCapabilities 类型的对象为 FirefoxOptions 类型的对象和启动 的webdriver

Web客户端 通过传递实例 FirefoxOptions 对象,如下所示:

System.setProperty("webdriver.gecko.driver", "gecko/linux/geckodriver");

FirefoxProfile profile = new FirefoxProfile();

profile.setPreference("network.proxy.no_proxies_on", "localhost");

profile.setPreference("javascript.enabled", true);

DesiredCapabilities capabilities = DesiredCapabilities.firefox();

capabilities.setCapability("marionette", true);

capabilities.setCapability(FirefoxDriver.PROFILE, profile);

FirefoxOptions options = new FirefoxOptions();

options.merge(capabilities);

options.setLogLevel(Level.FINEST);

options.addPreference("browser.link.open_newwindow", 3);

options.addPreference("browser.link.open_newwindow.restriction", 0);

WebDriver driver = new FirefoxDriver(options);


以上是 如何通过Java使用Selenium将功能和选项传递给Firefoxdriver 的全部内容, 来源链接: utcz.com/qa/398619.html

回到顶部