Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;) with Selenium, gradle and ChromeDriver

I am trying to use Selenium api with Gradle. This is my build.gradle dependency section:

dependencies {
    compile 'com.google.api-client:google-api-client:1.23.0'
    compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
    compile 'com.google.apis:google-api-services-sheets:v4-rev506-1.23.0'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version:        '2.9.0'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: '2.9.0' }

My selenium - Java code:

System.setProperty("webdriver.chrome.driver", "C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver = new ChromeDriver();

Code works fine, and I am able to get Chrome browser opened. However, in build.gradle, I am using 2.9.0 version of selenium and chromedriver. If I try to use any version after 2.9.0, it gives me below error in WebDriver driver = new ChromeDriver(); method:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
        at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
        at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
        at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
        at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
        at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
        at Quickstart.main(Quickstart.java:130)

I tried looking for gradle+Maven+selenium supported version. Was not able to find any good info. Any idea?

like image 281
Swati Thorve Avatar asked Mar 07 '23 19:03

Swati Thorve


1 Answers

Try to update your Guava to

<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>27.1-jre</version>
</dependency>

It will solve your issue.

like image 88
Reza Avatar answered Mar 10 '23 09:03

Reza