获取以下错误消息:处理程序调度失败;嵌套异常为java.lang.NoSuchMethodError.com.google.common.base.Prequisitions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/OObject;(V
同样的代码在我的本地mac中运行良好,但当它部署到redhat时,它无法创建chrome驱动程序。
pom-xml中的硒依赖性
<!-- Selenium Driver Dependencies-->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>2.33.2</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>
这是获得chrome驱动程序的方法:
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.util.concurrent.TimeUnit;
@PostConstruct
public void setChromDriverLocation(){
System.setProperty("webdriver.chrome.driver", this.chromeDriverLocation);
}
public WebDriver getChromeDriver(Long timeoutInSeconds){
this.LOGGER.info(String.format("Preparing to retrieve chrome driver %s", this.chromeDriverLocation));
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
options.addArguments("disable-gpu");
if(StringUtils.hasText(this.chromeBinaryPath)){
this.LOGGER.info(String.format("Setting binary path %s", this.chromeBinaryPath));
options.setBinary(this.chromeBinaryPath);
}
this.LOGGER.info("Getting chrome driver");
WebDriver chromeDriver = new ChromeDriver(options);
chromeDriver.manage().timeouts().implicitlyWait(timeoutInSeconds, TimeUnit.SECONDS);
this.LOGGER.info("Successfully retrieved chrome driver");
return chromeDriver;
}
它在以下行失败:WebDriver chromeDriver=新的chromeDriver(选项(;
谷歌chrome版本:谷歌chrome 81.0.4044.138并且安装了用于相同版本的chrome驱动程序。
chrome驱动程序执行良好并且
请让我知道任何解决方案或缺少的依赖项。
如果其他人也有类似的问题。问题是在服务器上的$PATH下设置了一个旧的谷歌番石榴库,导致了上述问题。
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0</version>
</dependency>
一旦从路径中删除了依赖项,以下就是运行selenium驱动程序所需的全部内容。
<!-- Selenium Driver Dependencies-->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.141.59</version>
</dependency>
如果其他人有上述问题,请检查类路径是否存在依赖性问题,并确保旧的谷歌语言库不是类路径的一部分。