devsda
devsda

Reputation: 4222

Java code throws exception after adding Selenium-java-2.31.0 library in Maven

I am working on Netbeans. I added a library selenium-java-2.31.0. But it shows exception. I added all the libraries on which this library is dependent.

I follow this link to add library in netbeans.

My code :-

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public static void main(String[] args) throws IOException, URISyntaxException {
        String url1 = "http://www.jabong.com/giordano-P6868-Black-Analog-Watch-183702.html";


        Document doc1 = Jsoup.connect(url1).get();

        WebDriver driver = new FirefoxDriver();
        driver.get(url1);  


        Elements tag_list = doc1.getAllElements();

        for( Element tag1 : tag_list ) {
            Point point=driver.findElement(By.id(tag1.id())).getLocation();  
            System.out.println("X Position : " + point.x);  
            System.out.println("Y Position : " + point.y);

        }
}

Exception

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Function
    at template_matching.Template_matching.main(Template_matching.java:275)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 1 more
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)

Help me in solving this problem. Why this exception throws?

Edit No. 1

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException
    at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:89)
    at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:79)
    at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:67)
    at org.openqa.selenium.firefox.FirefoxDriver.getProfile(FirefoxDriver.java:260)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:236)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
    at template_matching.Template_matching.main(Template_matching.java:275)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 11 more
Java Result: 1

Edit no.2

Now I moved to maven, by thinking it downloads all the dependent libraries. But now it shows diffrerent error.

enter image description here

Edit No. 3

As it shows some problem with firefox, I replaced firefox with Chrome. This time previous error is removed. But a new comes in picture. Please see this.

enter image description here

Edit no. 4

enter image description here

Edit No. 5

Now I shifted to firefox again, and gets given page, but it stucks then. Why ?

Below is the error snapshot that I got.

enter image description here

Upvotes: 0

Views: 7670

Answers (2)

Naveen
Naveen

Reputation: 139

I think you could have created a maven project which will solve your dependency problem related to the selenium.

Upvotes: 0

Tyler Main
Tyler Main

Reputation: 153

I believe the problem you are seeing at this point is due to you passing in driver.get("url1");

I think you mean to be passing in driver.get(url1); (Notice no quotation marks)

To expand on it a little bit, the reason it is throwing the malformed uri exception is that the uri being passed in (url1) does not contain any protocol (http/https).

Upvotes: 3

Related Questions