2

I'm having problems having my Java app accessing chromedriver, I've checked with htop:

    $htop
    PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
    22459 root       20   0 16632  7896  6820 S  0.0  0.8  0:00.06 sshd: root@pts/1
    22380 root       20   0 2690M  700M 12172 S  0.0 70.9  0:00.19 java -jar backend-server-0-SNAPSHOT-microbundle.jar --logToFile backend.log
    22214 root       20   0 2690M  700M 12172 S  0.0 70.9  0:00.09 java -jar backend-server-0-SNAPSHOT-microbundle.jar --logToFile backend.log
    22340 root       20   0 2690M  700M 12172 S  0.0 70.9  0:00.01 java -jar backend-server-0-SNAPSHOT-microbundle.jar --logToFile backend.log
    22342 root       20   0 2690M  700M 12172 S  0.0 70.9  0:00.02 java -jar backend-server-0-SNAPSHOT-microbundle.jar --logToFile backend.log

Then inside the Java code:

System.setProperty("webdriver.chrome.driver", chromeDriverPath);
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors");
WebDriver driver = new ChromeDriver(options);

However this throws:

Caused by: java.lang.NoSuchMethodError: 'void com.google.common.base.Preconditions.checkState(boolean, java.lang.String, java.lang.Object, java.lang.Object, java.lang.Object)'
        at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:125)
        at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
        at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:156)
        at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:346)
        at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:91)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157) 

Prior to this, the chromedriver was installed via (I'm using a Debian server):

sudo mv chromedriver /usr/bin/chromedriver
sudo chown root:root /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver

And checking chromedriver and Google chrome:

root@localhost:~# /usr/bin/chromedriver --version
ChromeDriver 85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689})
root@localhost:~# google-chrome --version
Google Chrome 85.0.4183.102

I'm wondering why the Java app is unable to execute the driver?

quarks
  • 33,478
  • 73
  • 290
  • 513
  • I've tested on a Windows machine, same code binary jar and the code works. The only problem is with the Linux/Debian machine. – quarks Sep 13 '20 at 09:44

1 Answers1

0

This is because you are using the old guava jar. If you update to latest or guava-21.0.jar then this problem will get resolved.

download updated guava jar https://github.com/google/guava/wiki/Release22

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>23.0</version>
</dependency>
 
Anirudh Jadhav
  • 967
  • 1
  • 9
  • 23