我正在尝试GeckoDriver
在selenium-java 3.11
. 火狐版本是59
. 一切正常,并且能够调用 firefox 驱动程序。唯一的挑战是我需要添加DesiredCapabilities
到我的 Firefox 实例中。
最新硒版本中的旧方法WebDriver driver = new FirefoxDriver(capabilities);
似乎已被弃用,并且无法找出指定功能的新方法。
这是代码:
public static WebDriver createDriver(String userAgentKey, String PROXY) {
File modifyHeaders = null;
try {
modifyHeaders =
ResourceUtils.getFile("classpath:modify_headers-0.7.1.1-fx.xpi"); //am adding the extension using DesiredCapabilities
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
Proxy proxy = new Proxy();
proxy.setHttpProxy(PROXY).setFtpProxy(PROXY).setSslProxy(PROXY);
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("javascript.enabled", true);
profile.setPreference("brower.link.open_newwindow", 1);
profile.setPreference("modifyheaders.config.active", true);
profile.setPreference("modifyheaders.config.alwaysOn", true);
profile.setPreference("modifyheaders.headers.count", 1);
profile.setPreference("modifyheaders.headers.action0", "Add");
profile.setPreference("modifyheaders.headers.name0", "Proxy-Authorization");
profile.setPreference("modifyheaders.headers.value0", "Basic dnNodWtsYUBleHBlZGlhLmNvbTpxZWxsYWZraw==");
profile.setPreference("modifyheaders.headers.enabled0", true);
profile.addExtension(modifyHeaders);
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setCapability(FirefoxDriver.PROFILE, profile);
cap.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.gecko.driver","/Users/vshukla/Music/geckodriver");
WebDriver driver = new FirefoxDriver(cap); //this is deprecated
return driver;
如何使用 DesiredCapabilities 将扩展添加到实例?实现这一目标的其他选择是什么?