maven selenium-java,在Maven中添加Selenium-java-2.31.0库后,Java代码抛出异常

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.(FirefoxProfile.java:89)

at org.openqa.selenium.firefox.FirefoxProfile.(FirefoxProfile.java:79)

at org.openqa.selenium.firefox.FirefoxProfile.(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.(RemoteWebDriver.java:110)

at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:190)

at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:183)

at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:179)

at org.openqa.selenium.firefox.FirefoxDriver.(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.

rWMpU.jpg

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.

v2P0O.jpg

Edit no. 4

N18UZ.jpg

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.

Dfmdk.jpg

解决方案

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).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值