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

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

问题描述:

出现以下错误:

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

跑步时

System.setProperty("webdriver.chrome.driver", "/ocs/browserDrivers/chromedriver.exe");
//ChromeOptions chromeOptions = new ChromeOptions();
//chromeOptions.addArguments("start-maximized");
driver = new ChromeDriver();

已升级到硒3.14和chromedriver 2.42.不是maven项目

Upgraded to selenium 3.14 and chromedriver 2.42.Not a maven project

此错误消息...

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

...表示执行该行时出现错误:

...implies that there was an error raised while executing the line:

System.setProperty("webdriver.chrome.driver", "/ocs/browserDrivers/chromedriver.exe");

您的主要问题是 WebDriver 二进制类型与基础操作系统之间的不兼容性.

Your main issue is the incompatibility between the WebDriver binary type and the underlying Operating System.

您需要从

  • Linux操作系统:

    • Linux OS:

    chromedriver_linux64.tar.gz 2018-09-13 19:30:37 3.85MB
    

  • MAC OS:

  • MAC OS:

    chromedriver_mac64.tar.gz   2018-09-13 18:14:11 5.75MB
    

  • Windows操作系统:

  • Windows OS:

    chromedriver_win32.zip  2018-09-13 21:11:33 3.42MB
    

  • 如果您使用的是 MAC OS ,则System.setProperty()行应为:

    If you are using MAC OS so the System.setProperty() line would be:

    System.setProperty("webdriver.chrome.driver", "/ocs/browserDrivers/chromedriver"); //drop the extension (.exe) part
    

    如果您使用的是 Windows操作系统,则System.setProperty()行应为:

    If you are using Windows OS so the System.setProperty() line would be:

    System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe"); //mention the absolute path