简体   繁体   中英

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;I)V with IE and Selenium through Java

I am trying to use selenium with sikuli.So sikuli would not run on a 64 bit using the current java set up so in my project changed the runtime to point to a 32 bit runtime environment and added my selenium jars using the 32 bit iewebdriver now I have a problem with the above Looked every where on the net added the guava.jar file v.21 it did not solve the problem changed that to the guava 26jre.jar and still nothing is working here is my code and errors if anyone can spot where I am going wrong

error

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;I)V
at org.openqa.selenium.remote.service.DriverService$Builder.usingPort(DriverService.java:285)
at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:242)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:211)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:150)
at riOSikuliAutomation.RiOSikuliAutomation.main(RiOSikuliAutomation.java:33)

and here is my code

DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability("nativeEvents", false);
cap.setCapability("unexpectedAlertBehaviour", "accept");
cap.setCapability("ignoreProtectedModeSettings", true);
cap.setCapability("disable-popup-blocking", true);
cap.setCapability("enablePersistentHover", true);
cap.setCapability("ignoreZoomSetting", true);
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
InternetExplorerOptions options = new InternetExplorerOptions();
options.merge(cap);
System.setProperty("webdriver.ie.driver", "C:\\Users\\Selenium\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(options);

as soon as it reads the last line the error pops up, anything I am not doing right please advise ?

我的依赖

This error message...

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;I)V

...implies that the IEDriverServer was unable to initiate/spawn a new WebBrowsing Session ie InternetExplorer Browser session.

Your main issue is the incompatibility between the version of the binaries you are using as follows:

  • You have mentioned about using guava-21.0-jre.jar which is pretty ancient .

Solution

Solution to your question would be either/all of the following steps:

  • Upgrade Selenium to current levels Version 3.14.0 which includes guava-25.0-jre .
  • Upgrade Guava to current levels of 26.0-jre (as per Selenium v3.14.0 Java clients).

    • Maven Dependency is as follows:

       <!-- https://mvnrepository.com/artifact/com.google.guava/guava --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>26.0-jre</version> </dependency>
  • Ensure you don't have several versions in your dependency tree.

    • To look for the existing guava versions through Maven use the command:

       mvn dependency:tree | less
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.

  • If issue still persists delete the MAVEN_HOME directory .m2 and download the binaries afresh.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM