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

前端 未结 7 1672
别跟我提以往
别跟我提以往 2020-11-27 08:28

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

dependencies {
    compile \'com.google.api-client:google-api-clien         


        
相关标签:
7条回答
  • 2020-11-27 09:21

    This error message...

    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
    

    ...implies that the Java Client was unable to find ChromeDriver().

    Issue & Solution

    As per the Selenium - Java code you have shared, the System.setProperty() line is used to set the ChromeDriver binary path not the chrome binary path. For that you have to download the ChromeDriver binary from the ChromeDriver - WebDriver for Chrome and place it in your system and mention the absolute path of the ChromeDriver through System.setProperty() line. Hence you have to change :

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

    To :

    System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    
    0 讨论(0)
提交回复
热议问题