When I try launching new Selenium/Firefox
instance with DesiredCapabilities
and FirfoxOptions
I get the following code:
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.firefox.FirefoxOptions.merge(Lorg/openqa/selenium/Capabilities;)Lorg/openqa/selenium/firefox/FirefoxOptions;
I am using the following code:
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;
}
My POM
file contains the following entries:
<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>
Previously, I had version 3.5.2 of org.seleniumhq.selenium
in POM which does not support merge
functionality. However, when I tried launching Selenium with version 3.5.2
using following code:
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);
I got the following exception:
NoSuchMethodError: org.openqa.selenium.firefox.FirefoxOptions.<init>(Lorg/openqa/selenium/Capabilities;)V
I have latest version of geckodriver.exe
installed.
Neither version 3.11.0 or version 3.5.2 is working (I also tried 3.8.2).
What am I doing wrong?
Thanks!
UPDATE:
With version 3.11.0 I get the following stack trace:
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)
With version 3.5.2 the following is the stack trace:
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)
The method getTMPFirefoxProfile()
basically does the following:
if (firefoxOptions != null) {
driver = new FirefoxDriver(firefoxOptions);
} else {
driver = new FirefoxDriver();
}
Thanks!!