user2805845
user2805845

Reputation: 53

Unable to run selenium web driver project for 3.8.1 version

Unable to run web driver 3.8.1 geckodriver 0.19.1 with guava 21 and 22 . Firefox version 58.0.2 (64-bit) getting error as :

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V

running on iMac

System.setProperty("webdriver.gecko.driver", "//Users//(username)//Downloads//engage-test//engage-test-common//exes//geckodriver");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver= new FirefoxDriver(capabilities);

Upvotes: 0

Views: 741

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193108

The error says it all :

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V

Class NoSuchMethodError

public class NoSuchMethodError extends IncompatibleClassChangeError and as per the Java Docs it is thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method. Normally, this error is caught by the compiler and this error can only occur at run time if the definition of a class has incompatibly changed.

Solution

Perform the following steps :

  • When providing absolute paths either use double back slashes (\\) or single front slashes (/). Both are equivalent. So you need to update the System.setProperty() as follows :

    System.setProperty("webdriver.gecko.driver", "/Users/<username>/Downloads/engage-test/engage-test-common/exes/geckodriver"); //Linux Style
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", true);
    
  • Update your JDK to the most recent versions JDK 8u161

  • Upgrade Selenium-Java Clients to v3.10.0.
  • Clean up the Project Space from your IDE.
  • Run CCleaner tool to wipe off all the OS system chores.
  • If your base Web Browser version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of the Web Browser.
  • Take a System Reboot.
  • Execute your @Test

Update

As you are using Selenium-Java Client 3.11.0 where support of DesiredCapabilities is deprecated from the list of constructors for FirefoxDriver Class you have to use the method merge(Capabilities extraCapabilities) and merge the capabilities into an FirefoxOptions Class object as follows :

package demo;

import java.util.logging.Level;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

public class A_Firefox_DC_Opt 
{
    public static void main(String[] args) 
    {
        System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
        DesiredCapabilities dc = new DesiredCapabilities();
        dc.setCapability("marionatte", true);
        FirefoxOptions opt = new FirefoxOptions();
        opt.merge(dc);
        FirefoxDriver driver =  new FirefoxDriver(opt);
        driver.get("https://stackoverflow.com");
        System.out.println("Application opened");
        System.out.println("Page Title is : "+driver.getTitle());
        driver.quit();
    }
}

Console Output :

1522037759633   geckodriver INFO    geckodriver 0.20.0
1522037759653   geckodriver INFO    Listening on 127.0.0.1:20073
1522037760415   mozrunner::runner   INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\ATECHM~1\\AppData\\Local\\Temp\\rust_mozprofile.hRnaFvWiVBua"
1522037762202   Marionette  INFO    Enabled via --marionette
1522037765376   Marionette  INFO    Listening on port 1176
1522037765636   Marionette  WARN    TLS certificate errors will be ignored for this session
Mar 26, 2018 9:46:05 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Application opened
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers

Upvotes: 1

Related Questions