当我尝试启动新Selenium/Firefox
实例时DesiredCapabilities
,FirfoxOptions
我得到以下代码:
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.firefox.FirefoxOptions.merge(Lorg/openqa/selenium/Capabilities;)Lorg/openqa/selenium/firefox/FirefoxOptions;
我正在使用以下代码:
public WebDriver getDriver() throws MalformedObjectNameException, InstanceNotFoundException, ReflectionException, InterruptedException
{
System.setProperty("webdriver.gecko.driver", GlobalVar.geckdriverExecutableFilePath);
//DesiredCapabilities capabilities = new DesiredCapabilities();
DesiredCapabilities dc = DesiredCapabilities.firefox();
if (proxyPOJO != null) {
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyPOJO.getProxyIP() + ":" + proxyPOJO.getProxyPort());
proxy.setFtpProxy(proxyPOJO.getProxyIP() + ":" + proxyPOJO.getProxyPort());
proxy.setSslProxy(proxyPOJO.getProxyIP() + ":" + proxyPOJO.getProxyPort());
dc.setCapability(CapabilityType.PROXY, proxy);
}
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
opt.addPreference("dom.popup_maximum", 200);
opt.addPreference("dom.webnotifications.enabled", false);
opt.merge(capabilities);
WebDriver driver = WebDriverX.getNewFireFoxWebDriver(opt); // Basically calls: driver = new FirefoxDriver(firefoxOptions);
return driver;
}
我的POM
文件包含以下条目:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.11.0</version>
</dependency>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>26.0-jre</version>
</dependency>
以前,我org.seleniumhq.selenium
在 POM 中拥有不支持merge
功能的 3.5.2 版本。但是,当我尝试3.5.2
使用以下代码启动带有版本的 Selenium 时:
System.setProperty("webdriver.gecko.driver", GlobalVar.geckdriverExecutableFilePath);
DesiredCapabilities capabilities = new DesiredCapabilities();
if (proxyPOJO != null) {
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyPOJO.getProxyIP() + ":" + proxyPOJO.getProxyPort());
proxy.setFtpProxy(proxyPOJO.getProxyIP() + ":" + proxyPOJO.getProxyPort());
proxy.setSslProxy(proxyPOJO.getProxyIP() + ":" + proxyPOJO.getProxyPort());
capabilities.setCapability(CapabilityType.PROXY, proxy);
}
FirefoxOptions firefoxOptions = new FirefoxOptions(capabilities);
WebDriver driver = WebDriverX.getNewFireFoxWebDriver(firefoxOptions);
我得到以下异常:
NoSuchMethodError: org.openqa.selenium.firefox.FirefoxOptions.<init>(Lorg/openqa/selenium/Capabilities;)V
我已经geckodriver.exe
安装了最新版本。
版本 3.11.0 或版本 3.5.2 都不起作用(我也尝试过 3.8.2)。
我究竟做错了什么?
谢谢!
更新:
使用 3.11.0 版本,我得到以下堆栈跟踪:
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.firefox.FirefoxOptions.merge(Lorg/openqa/selenium/Capabilities;)Lorg/openqa/selenium/firefox/FirefoxOptions;
at webdriverX.WebDriverProfile.getTMPFirefoxProfile(WebDriverProfile.java:259)
at s.SPage.scrapeS(SPage.java:36)
at n.NMain.main(NMain.java:27)
对于 3.5.2 版本,以下是堆栈跟踪:
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.firefox.FirefoxOptions.<init>(Lorg/openqa/selenium/Capabilities;)V
at webdriverX.WebDriverProfile.getTMPFirefoxProfile(WebDriverProfile.java:232)
at s.SPage.scrapeS(SPage.java:36)
at n.NMain.main(NMain.java:27)
该方法getTMPFirefoxProfile()
主要执行以下操作:
if (firefoxOptions != null) {
driver = new FirefoxDriver(firefoxOptions);
} else {
driver = new FirefoxDriver();
}
谢谢!!