Chrome驱动程序异常NoSuchMethodError

时间:2017-03-24 05:06:51

标签: java unit-testing selenium-chromedriver

我正在尝试编写测试用例,使用ChromeDriver,但在尝试初始化ChromeDriver实例时获取异常,

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:111)
    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:302)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
    at DemoTests.test(DemoTests.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

在努力,但无法解决它。我该如何解决这个问题?以下是我的代码库,

@Test
public void test() {
    ChromeDriver driver = new ChromeDriver();
    driver.manage().window().maximize();

    driver.get("www.google.com");
} 

4 个答案:

答案 0 :(得分:3)

您似乎使用的是Google番石榴的错误版本。检查您正在使用的版本的Web驱动程序文档,以查看应使用的番石榴版本。

答案 1 :(得分:1)

通常,当您使用&gt; 45版本的chrome和selenium webdriver&lt;时,会出现此错误。 3版。

解决的最佳方法是升级您的selenium webdriver版本 http://www.seleniumhq.org/download/
在Selenium Client&amp;下载selenium-java-3.4.0.zip。 WebDriver语言绑定

答案 2 :(得分:0)

确保Selenium Webdriver版本中没有不匹配的地方。例如,确保C:\ Program Files \ SmartBear \ SoapUI-5.4.0 \ bin \ lib和C:\ Program Files \ SmartBear \ SoapUI-5.4.0 \ bin和C:\ Program Files \ SmartBear \如果您是从SOAPUI Groovy运行,则为SoapUI-5.4.0 \ bin \ ext

答案 3 :(得分:0)

添加以下依赖项以解决此问题:

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client</artifactId>
        <version>1.28.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>23.0</version>
    </dependency>