java.lang.NoSuchMethodError:带有硒,gradle和ChromeDriver的com.google.common.base.Preconditions.checkState(ZLjava/lang/String;) [英] java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;) with Selenium, gradle and ChromeDriver

查看:335
本文介绍了java.lang.NoSuchMethodError:带有硒,gradle和ChromeDriver的com.google.common.base.Preconditions.checkState(ZLjava/lang/String;)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将Selenium api与Gradle一起使用.这是我的build.gradle依赖项:

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' }

我的硒-Java代码:

My selenium - Java code:

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

代码工作正常,并且能够打开Chrome浏览器. 但是,在build.gradle中,我正在使用2.9.0版本的selenium和chromedriver.如果我尝试使用2.9.0之后的任何版本,则会在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)

我尝试寻找gradle + Maven + Selenium支持的版本.找不到任何好的信息.任何的想法?

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

推荐答案

尝试将您的番石榴更新为

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>

它将解决您的问题.

这篇关于java.lang.NoSuchMethodError:带有硒,gradle和ChromeDriver的com.google.common.base.Preconditions.checkState(ZLjava/lang/String;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆