I am trying to scrape data from a site I did code for. I want to scrape data on button click event but when I run my program it throws an exception

Exception is: java.lang.NoClassDefFoundError: com/google/common/base/Function

How can I remove this exception and work my program

Here is my code which I tried

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class GetData {

    public static void main(String args[]) throws InterruptedException {
        WebDriver driver = new FirefoxDriver();
        // select barge
        new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_ddl_commodity"))).selectByVisibleText("Jo");
        // click button

        //get only table tex
        WebElement findElement = driver.findElement(By.className("grid-view"));
        String htmlTableText = findElement.getText();
        // do whatever you want now, This is raw table values.


  • Can you tell us what jar files have you included? – t3hn00b Apr 2 '14 at 11:34

This error means that you have forgotten to include a dependency in your project. It's been suggested on stackoverflow that the dependency you forgot might well be selenium-server-standalone-version.jar. Does adding that jar to your project help?

| improve this answer | |

I believe this will help. Same question basically and this seems to be pretty common.


I think that is what t3hnoob was getting after as well.

| improve this answer | |

A NoClassDefFoundError is thrown when the JRE can't find a class. In your case, it can't find the class com.google.common.base.Function, which is not added to your classpath.

Add the guava-18.0.jar to the classpath of the project.


| improve this answer | |

Actually 'throws exceptions' is the only way to get error.

If error comes from your setup or dependency it will not shown If you remove throws statement.

If you are not confident about which exception is coming then write 'throws Exception'. It will throw all exception by default.

Now come to your question.

Your code perfectly fine working. Just check your jar file and classpath.

Also check your JRE and clean your project.

Thank you.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.