Code trials:
package SeleniumSessions;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestChrome {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.google.com");
}
}
Error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
at org.openqa.selenium.chrome.ChromeDriver$ChromeDriverCommandExecutor.getExtraCommands(ChromeDriver.java:122)
at org.openqa.selenium.chrome.ChromeDriver$ChromeDriverCommandExecutor.<init>(ChromeDriver.java:118)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:106)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:93)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:48)
at SeleniumSessions.TestChrome.main
Error snapshot:

Advertisement
Answer
This error message…
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
…implies that the file com/google/common/collect/ImmutableMap might be corrupted or there is some incompatibility between the version of the binaries you are using.
Further you need to take care of a couple of things as follows:
Instead of storing the
chromedriver.exebinary right underC:try to put it within a directory asC:\BrowserDrivers\chromedriver.exeand change theSystem.setProperty()line accordingly. So effectively, the line of code will be:System.setProperty("webdriver.gecko.driver","C:\BrowserDrivers\chromedriver.exe");
Also ensure that:
- JDK is upgraded to current levels JDK 8u311.
- Selenium is upgraded to current released Version 4.1.3.
- ChromeDriver is updated to current ChromeDriver v100.0 level.
- Chrome Browser is updated to current chrome=100.0 (as per chromedriver=100.0.4896.60 release notes).
Reference
You can find a relevant discussion in: