Selenium: Infamous java.lang.NoClassDefFoundError: com/google/common/base/Function at creating chromedriver instance with new selenium 3.3.1

Created on 5 Apr 2017  Â·  20Comments  Â·  Source: SeleniumHQ/selenium

Meta -

OS: Windows 7 64b
Selenium Version: client-combined-3.3.1-nodeps.jar
Browser: ChromeDriver
Compiler: Netbeans 8.2 with Selenium 3.3.1 running on Java SE 8 (no maven, no anything else added)

Hi I started developing in Java for selenium and I am lost in what to do as I am getting infamous error:

"Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
at selenium.demos.SeleniumDemos.main(SeleniumDemos.java:21)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
C:Users\admin\AppData\Local\NetBeans\Cache\8.2executor-snippetsrun.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)"

at the very basic code in line that creates new ChromeDriver() instance:

package selenium.demos;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
/**
*

  • @author admin
    */
    public class SeleniumDemos {
/**
 * @param args the command line arguments
 */
private static WebDriver driver = null;
public static void main(String[] args) {
   System.setProperty( "webdriver.chrome.driver", "C:\\Users\\admin\\Desktop");
   driver = new ChromeDriver();
   driver.get("https:\\google.com");
}

}

I am lost as same setup worked for youtuber : https://www.youtube.com/watch?v=lm2n7YOSD3Y and its no longer working and I don't know why or how to debug it as it is my first time with Java Selenium

Most helpful comment

SOLVED:

Ok so finnaly I switched to Eclipse Neon. _Downloaded selenium with all 78 dependencies requited from_ _https://jar-download.com/?search_box=selenium-java-3.3.1 and downloaded chromedriver 2.25_ from 2017 instead of 2.9 from 2014 and it worked.

Summarizing: "all jars connected" jar file that is served by seleniumhr as "all you need" is missing a lot dependencies and nowhere is said that you need more...till you try to lauch first test. Only at jar-download you can get all dependencies junit included in one zip file when you request selenium with dependencies. It is easy for people that were working as java developers already...but hard to understand for people that are switching language (as me) or start with selenium.

List of dependencies for selenium 3.3.1 and chromedriver.exe 2.25 (For Selenium+Java project):
ant-1.9.6
ant-launcher-1.9.6
aopalliance-repackaged-2.4.0-b09
asm-5.1
aspectjweaver-1.8.10
cglib-3.2.4
cglib-nodep-3.2.4
commons-beanutils-1.9.2
commons-codec-1.10
commons-collections-3.2.2
commons-digester-1.8.1
commons-exec-1.3
commons-io-2.5
commons-lang3-3.5
commons-logging-1.2
commons-validator-1.5.1
cssparser-0.9.21
eyes-common-java-2.56
eyes-connectivity-java-jersey2x-2.56
eyes-sdk-java-jersey2x-2.56
eyes-selenium-java-2.56
gson-2.8.0
guava-21.0
hamcrest-core-1.3
hamcrest-library-1.3
hk2-api-2.4.0-b09
hk2-locator-2.4.0-b09
hk2-utils-2.4.0-b09
htmlunit-2.24
htmlunit-core-js-2.23
htmlunit-driver-2.24
httpclient-4.5.2
httpcore-4.4.4
httpmime-4.5.2
imgscalr-lib-4.2
jackson-annotations-2.5.0
jackson-core-2.5.1
jackson-databind-2.5.1
java-client-5.0.0-BETA6
javassist-3.18.1-GA
javax.annotation-api-1.2
javax.inject-2.4.0-b09
javax.ws.rs-api-2.0.1
jersey-apache-connector-2.16
jersey-client-2.16
jersey-common-2.16
jersey-guava-2.16
jetty-io-9.2.20.v20161216
jetty-util-9.2.20.v20161216
jna-4.1.0
jna-platform-4.1.0
junit-4.12
neko-htmlunit-2.24
osgi-resource-locator-1.0.1
phantomjsdriver-1.4.0
sac-1.3
selenium-api-3.3.1
selenium-chrome-driver-3.3.1
selenium-edge-driver-3.3.1
selenium-firefox-driver-3.3.1
selenium-ie-driver-3.3.1
selenium-java-3.3.1
selenium-opera-driver-3.3.1
selenium-remote-driver-3.3.1
selenium-safari-driver-3.3.1
selenium-support-3.3.1
serializer-2.7.2
spring-aop-4.3.5.RELEASE
spring-beans-4.3.5.RELEASE
spring-context-4.3.5.RELEASE
spring-core-4.3.5.RELEASE
spring-expression-4.3.5.RELEASE
websocket-api-9.2.20.v20161216
websocket-client-9.2.20.v20161216
websocket-common-9.2.20.v20161216
xalan-2.7.2
xercesImpl-2.11.0
xml-apis-1.4.01

All 20 comments

I use chromedriver for windows from this page: https://chromedriver.storage.googleapis.com/index.html?path=2.29/

System.setProperty( "webdriver.chrome.driver", "C:\Users\admin\Desktop");

set this to C:\\Users\\admin\\Desktop\\chromedriver.exe ?

Whoops hit the wrong button

In the youtube video you referenced, it shows escaping the \ and adding chromedriver.exe

tryied already System.setProperty( "webdriver.chrome.driver", "C:\Users\admin\Desktop\chromedriver.exe"); but it didn't worked - same error.

Before closing issue meybe ask if your advice worked? Answer : It didn't.

Please ensure you're using guava 21 by manually including it as a dependency or making sure your other deps are up to date.

tryied already System.setProperty( "webdriver.chrome.driver", "C:Users\admin\Desktopchromedriver.exe"); but it didn't worked - same error.

You didn't escape the backslashes, try that

@MartaWdowicka @Jarob22 has informed me that this appears to be a dependency issue. Please try that, I will re-open the issue.

  1. I escaped backslashes - just netbeans 8.2 adding it for me when I paste url and when I copy it to keyboard it erases escaping. - to not escape escaped backslashesh if someone just want to copy this lane between projects. It is normal.
  2. I am running that test in normal Java Application project without any Maven or Guava. And I seeked help, but didn't understand what maven have to do with my problem as I am not even using it. Only reasonable answer to that problem was that there are old dependency - but I have fresh instalation of everything. no old dependencies.

Hi Marta,

I'm answering because I came across this exact issue when I did a recent upgrade. Please make sure that you're using the latest version of junit if you're using it, and what else I found worked for me was importing selenium-support and selenium-server artifacts from the org.seleniumhq.selenium group.

The selenium library depends upon other libraries that need to be on your java classpath, like guava. I'd recommend using the standalone server instead of the "no-deps" jar, which has no external dependencies included.

Please follow up on either IRC or the selenium-users google group if you continue to have issues.

Thank you will try your tips Jarob -
So I am in a hell loop of missing dependencies:

  1. After I added Guava 21.0 it requested:

java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials

  1. So I added httpcomponents-httpclient-4.5.2.jar
  2. Which further required httpcomponents-httpcore-4.4.4.jar
  3. Then I was forced to add apache-commons.jar because it lacked logger and a few other files.
  4. Then I had to add slf4j.jar and finally my hello-word selenium project requested logback-core-0.9.6.jar file....
    and after I ALREADY ADDED IT... it requested another class from the same .jar. So FINALLY I got stuck with a .jar file requesting me to add the very same .jar file...as its dependency...and all that just to run "selenium3.3.1 hello word" sorry for being frustrated yesterday but its too illogical for me.
    Currently I see error: that requires file from logback-core-0.9.6.jar, but i already added that .jar

Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/classic/selector/ContextSelector
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:189)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:112)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:105)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:235)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:208)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:131)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:272)
at org.apache.http.conn.ssl.AbstractVerifier.(AbstractVerifier.java:60)
at org.apache.http.conn.ssl.AllowAllHostnameVerifier.(AllowAllHostnameVerifier.java:43)
at org.apache.http.conn.ssl.AllowAllHostnameVerifier.(AllowAllHostnameVerifier.java:45)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.(SSLConnectionSocketFactory.java:144)
at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:71)
at org.openqa.selenium.remote.internal.HttpClientFactory.(HttpClientFactory.java:57)
at org.openqa.selenium.remote.internal.HttpClientFactory.(HttpClientFactory.java:60)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.getDefaultHttpClientFactory(ApacheHttpClient.java:250)
at org.openqa.selenium.remote.internal.ApacheHttpClient$Factory.(ApacheHttpClient.java:227)
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:92)
at org.openqa.selenium.remote.HttpCommandExecutor.(HttpCommandExecutor.java:71)
at org.openqa.selenium.remote.service.DriverCommandExecutor.(DriverCommandExecutor.java:62)
at org.openqa.selenium.chrome.ChromeDriverCommandExecutor.(ChromeDriverCommandExecutor.java:39)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:178)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:167)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:124)
at selenium.demos.SeleniumDemos.main(SeleniumDemos.java:22)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.selector.ContextSelector
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 25 more
C:Users\admin\AppData\Local\NetBeans\Cache\8.2executor-snippetsrun.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

Will try uninstalling Netbeans IDE 8.2 and installing it again... as it doesn't make sense if my installation is complete...so meybe it is broken. As all that are just basic files... (or at last it looks like they are)

SOLVED:

Ok so finnaly I switched to Eclipse Neon. _Downloaded selenium with all 78 dependencies requited from_ _https://jar-download.com/?search_box=selenium-java-3.3.1 and downloaded chromedriver 2.25_ from 2017 instead of 2.9 from 2014 and it worked.

Summarizing: "all jars connected" jar file that is served by seleniumhr as "all you need" is missing a lot dependencies and nowhere is said that you need more...till you try to lauch first test. Only at jar-download you can get all dependencies junit included in one zip file when you request selenium with dependencies. It is easy for people that were working as java developers already...but hard to understand for people that are switching language (as me) or start with selenium.

List of dependencies for selenium 3.3.1 and chromedriver.exe 2.25 (For Selenium+Java project):
ant-1.9.6
ant-launcher-1.9.6
aopalliance-repackaged-2.4.0-b09
asm-5.1
aspectjweaver-1.8.10
cglib-3.2.4
cglib-nodep-3.2.4
commons-beanutils-1.9.2
commons-codec-1.10
commons-collections-3.2.2
commons-digester-1.8.1
commons-exec-1.3
commons-io-2.5
commons-lang3-3.5
commons-logging-1.2
commons-validator-1.5.1
cssparser-0.9.21
eyes-common-java-2.56
eyes-connectivity-java-jersey2x-2.56
eyes-sdk-java-jersey2x-2.56
eyes-selenium-java-2.56
gson-2.8.0
guava-21.0
hamcrest-core-1.3
hamcrest-library-1.3
hk2-api-2.4.0-b09
hk2-locator-2.4.0-b09
hk2-utils-2.4.0-b09
htmlunit-2.24
htmlunit-core-js-2.23
htmlunit-driver-2.24
httpclient-4.5.2
httpcore-4.4.4
httpmime-4.5.2
imgscalr-lib-4.2
jackson-annotations-2.5.0
jackson-core-2.5.1
jackson-databind-2.5.1
java-client-5.0.0-BETA6
javassist-3.18.1-GA
javax.annotation-api-1.2
javax.inject-2.4.0-b09
javax.ws.rs-api-2.0.1
jersey-apache-connector-2.16
jersey-client-2.16
jersey-common-2.16
jersey-guava-2.16
jetty-io-9.2.20.v20161216
jetty-util-9.2.20.v20161216
jna-4.1.0
jna-platform-4.1.0
junit-4.12
neko-htmlunit-2.24
osgi-resource-locator-1.0.1
phantomjsdriver-1.4.0
sac-1.3
selenium-api-3.3.1
selenium-chrome-driver-3.3.1
selenium-edge-driver-3.3.1
selenium-firefox-driver-3.3.1
selenium-ie-driver-3.3.1
selenium-java-3.3.1
selenium-opera-driver-3.3.1
selenium-remote-driver-3.3.1
selenium-safari-driver-3.3.1
selenium-support-3.3.1
serializer-2.7.2
spring-aop-4.3.5.RELEASE
spring-beans-4.3.5.RELEASE
spring-context-4.3.5.RELEASE
spring-core-4.3.5.RELEASE
spring-expression-4.3.5.RELEASE
websocket-api-9.2.20.v20161216
websocket-client-9.2.20.v20161216
websocket-common-9.2.20.v20161216
xalan-2.7.2
xercesImpl-2.11.0
xml-apis-1.4.01

Hello,

I'm glad you got it sorted, but it seems like you weren't using any sort of dependency manager which is why you didn't have all those dependencies. Look up maven and see if you can learn how to use that, it will make your life much easier.

Also, you will want chromedriver 2.29, 2.25 is now a bit old and won't support the latest chrome in all things.

Well, one step at a time- it was my first time hearing about maven and word "dependency" 3 days ago and really wasn't sure how to use it at that time. It isn't same simple thing as NuGet or homebrew where you just need to type what you need and push enter to get anything installed :) Maven needs a lot of tutorials and understanding of enviroment to use.

P.S. Actualy it was 2.29 my bad - previous chromedriver versions that I used was trowing errors that totally blocked tests from running on current chrome- and that happened to me when I tryied 2.9. 2.9 currently trows security errors on certificates and automation plugins and don't even run driver.get without trowing connection reset exeption.

Its ok, I wasn't berating you, just trying to give some advice :) I think
we forget some people don't even know these things so I didn't even think
you wouldn't have a dependency manager! But maven is actually fairly simple
to get going, especially using Eclipse. Just setup a new maven project,
copy-paste the XML in that you get from the maven central repoository
website - https://mvnrepository.com/ and build the project. There shouldn't
be too much tutorials to get the hang of it :)

On Sat, Apr 8, 2017 at 7:55 PM, MartaWdowicka notifications@github.com
wrote:

Well, one step at a time- it was my first time hearing about maven and
word "dependency" 4 days ago and really wasn't sure how to use it at that
time. It isn't same simple thing as NuGet or homebrew where you just need
to type what you need and push enter to get anything installed :) Maven
needs a lot of tutorials and understanding of enviroment to use.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/SeleniumHQ/selenium/issues/3768#issuecomment-292738282,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABlEC8h_lMtSaxfCpJmx2a08WTXSmW33ks5rt9g5gaJpZM4M0NS6
.

2.9 is years old, 2.29 is the latest. I admit it is confusing because the listings for the chromedriver executeables have 2.9 at the bottom, because it's ordered alphabetically (9 comes after 2), not in version order.

Yeah like I expected that version 2.1922 is lower than 2.9 not newer (because 2.8 was under 2.9 on list)

Was this page helpful?
0 / 5 - 0 ratings