0

I'm getting: NoSuchMethodError: org.openqa.selenium.firefox.FirefoxOptions.merge when I try launching Selenium WebDriver:

My code in main calls a single method:

WebDriver driver = new WebDriverProfile().getTMPFirefoxProfile(null); // Parameter is optional

I am posting my code in detail in the hope that perhaps someone will be able to offer a suggestion to guide me in the right direction.

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:286)
    at n.NMain.main(NMain.java:22)

The call to getTMPFirefoxProfile(ProxyPOJO proxyPOJO) calls the code:

public WebDriver getTMPFirefoxProfile(ProxyPOJO proxyPOJO) throws InterruptedException, MalformedObjectNameException, InstanceNotFoundException, ReflectionException {

    System.setProperty("webdriver.gecko.driver", GlobalVar.geckdriverExecutableFilePath); // Verified path is correct via syso


    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);
    }


    DesiredCapabilities dc = DesiredCapabilities.firefox();


    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);      



    return driver;
}

The call to: getNewFireFoxWebDriver(FirefoxOptions firefoxOptions) calls this code:

if (firefoxOptions != null) {
    driver = new FirefoxDriver(firefoxOptions);
} else {
  driver = new FirefoxDriver();
}

 return driver;

I've asked a similar question however I've now tried almost 10 different suggestions - none of which solved my problem.

Below I will outline the steps I took to try to solve the problem:

1) Right clicked project -> Maven clean -> Maven build -> Maven test (I tried each one separately and then all one after the next)

2) Clicked Project -> clean

3) Confirmed Firefox is updated to latest version (version 72)

4) Removed the library guava (the only suggested conflict) from project POM

5) Shutdown and restarted Eclipse

6) Deleted all run configurations and ran project from scratch

7) Re-downloaded GeckoDriver v0.26.0 to make sure I have the lestest version installed

8) I Made sure my POM file contains Selenium dependency version 3.141.591 which contains merge method

I'm out of options.. What do I try next?

Below is the contents of the project POM file:

<dependencies>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>3.141.59</version>
    </dependency>

    <dependency>
        <groupId>edu.stanford.nlp</groupId>
        <artifactId>stanford-corenlp</artifactId>
        <version>3.9.2</version>
    </dependency>

    <dependency>
        <groupId>edu.stanford.nlp</groupId>
        <artifactId>stanford-corenlp</artifactId>
        <version>3.9.2</version>
        <classifier>models</classifier>
    </dependency>

    <dependency>
        <groupId>uk.ac.abdn</groupId>
        <artifactId>SimpleNLG</artifactId>
        <version>4.4.8</version>
    </dependency>

</dependencies>

I have two other projects linked in the build path of this project. From one project, I am able to call getTMPFirefoxProfile(ProxyPOJO proxyPOJO) without any issues. From the other one, I get the same error I get with current project. What does this mean? I analyzed the other project and I don't see any conflicting dependencies.

I spent the entire day trying to troubleshoot the issue but I feel completely lost..

Any ideas?

Thanks!

Alan Cook
  • 342
  • 3
  • 14

1 Answers1

0

After covering up all the possible issues and solution on this issue in your previous question seems you are quite close now.

Further, I would suggest to install Selenium libraries for Java using you should add the <selenium-java> dependency in your project pom.xml first as it would support running your automation project with all Selenium supported browsers.:

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>3.141.59</version>
</dependency>

Moving further, if you want to run tests only in Firefox, you can replace with the selenium-firefox-driver dependency:

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-firefox-driver</artifactId>
  <version>3.141.59</version>
</dependency>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • @Debanjan_B I added `selenium-java` to `POM` file to no avail. I suspect that `Java` is loading a previous version of Selenium due to transitive dependency of project in build path. However, every other project compiles to version `3.141.59`. How can I confirm this? Also, the exact same method call works flawlessly in another project - and the other project has all of the same projects (+ others) in it's build path. If it's indeed a question of transitive dependency, wouldn't it effect all projects equally? Why would exception be thrown from one, not the other? Thanks for being so helpful!! – Alan Cook Feb 06 '20 at 17:00
  • @Debanjan_B I wish to add that I confirmed `Selenium` complies to version `3.141.59` via `Dependency Hierarchy` in `Maven`. `Maven` shows `[compile]` next to this version. Is it possible `Maven` is showing `compile` next to the wrong version? If yes, how can I know? Also, I know that one project (indirectly referenced through build path of current project) has a library named [`AShot`] which relies on `Selenium Remote Driver version 2.5.3`. However, `Maven` says it is `omitted for conflict with version 3.141.59`. Moreover, the call to `getTMPFirefoxProfile()` actually works in that project.. – Alan Cook Feb 06 '20 at 17:13
  • @Debanjan_B After much troubleshooting I finally arrived at a solution. I created a new Library named `Project_Libs` Inside the Library I added Jar files of Selenium version `3.141.59`. Right clicked on Project -> Properties -> Java Build Path and added `Project_Libs` as Library to project. However, this alone did not solve my problem. In `Order and Export` panel I had to move `Project_Libs` up above another Library named `Libs` (below the `Maven` Library). I also had to manually add `Guava` Jars to this Library. Now it works!! Is there a way to avoid all this in the future? – Alan Cook Feb 06 '20 at 18:16
  • @AlanCook It won't be a good idea for me to comment further in case you are having [**transitive dependency**](https://en.wikipedia.org/wiki/Transitive_dependency) for multiple maven based projects, without seeing the error logs/exceptions or understanding them. However there is a chance of the shared jars getting corrupted for specific environments (os). – undetected Selenium Feb 06 '20 at 19:52
  • @AlanCook About your current solution: I won't be comfortable with that either as I suspect more conflicts surfacing in the form of [NoSuchMethodError](https://stackoverflow.com/questions/50465550/nosuchmethoderror-org-openqa-selenium-os-commandline-findexecutableljava-lang/50469053#50469053) or [NoClassDefFoundError](https://stackoverflow.com/questions/49622195/java-lang-noclassdeffounderror-org-apache-commons-exec-executor/49623324#49623324) surfacing when you would least expect them. Anyways, glad to know you have nailed the issue for the time being. – undetected Selenium Feb 06 '20 at 20:06