在Maven中添加Selenium-java-2.31.0库后,Java代码抛出异常 [英] Java code throws exception after adding Selenium-java-2.31.0 library in Maven

查看:264
本文介绍了在Maven中添加Selenium-java-2.31.0库后,Java代码抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Netbeans上工作。我添加了一个库selenium-java-2.31.0。但它显示异常。
我添加了这个库所依赖的所有库。



我遵循这个

我的代码: -

  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 - 模拟 - 手表-183702.html;


文档doc1 = Jsoup.connect(url1).get();

WebDriver驱动程序=新的FirefoxDriver();
driver.get(url1);


元素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);

}
}

异常

 线程main中的异常java.lang.NoClassDefFoundError:com / google / common / base / Function 
在template_matching.Template_matching.main(Template_matching.java:275)
导致:java.lang.ClassNotFoundException:com.google.common.base.Function
在java.net.URLClassLoader $ 1.run(URLClassLoader .java:366)
在java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)
在java.security.AccessController.doPrivileged(本机方法)
在java.net。 URLClassLoader.findClass(URLClassLoader.java:354)
在java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308)
在java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1更多
Java结果:1
BUILD SUCCESSFUL(总时间:2秒)

帮我解决这个问题LEM。为什么这个例外会抛出?



编辑1

 code>线程main中的异常java.lang.NoClassDefFoundError:org / pson / JSONException 
在org.openqa.selenium.firefox.FirefoxProfile。< init>(FirefoxProfile.java:89)
在org.openqa.selenium.firefox.FirefoxProfile。< init>(FirefoxProfile.java:79)
在org.openqa.selenium.firefox.FirefoxProfile。< init>(FirefoxProfile.java:67)
在org.openqa.selenium.firefox.FirefoxDriver.getProfile(FirefoxDriver.java:260)
在org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:236)
在org.openqa.selenium.remote.RemoteWebDriver。< init>(RemoteWebDriver.java:110)
在org.openqa.selenium.firefox.FirefoxDriver。< init>(FirefoxDriver.java:190)
在org.openqa.selenium.firefox.FirefoxDriver。< init>(FirefoxDriver.java:183)
在org.openqa.selenium.firefox.FirefoxDriver。< init>(FirefoxDriver.java:1 79)
在org.openqa.selenium.firefox.FirefoxDriver。< init>(FirefoxDriver.java:92)
在template_matching.Template_matching.main(Template_matching.java:275)
导致作者:java.lang.ClassNotFoundException:java.net.URLClassLoader $ 1.run $ URBlassLoader.java $ 36 $ b $ java.lang.classNotFoundException:org.json.JSONException
java.net.URLClassLoader $ 1.run(URLClassLoader.java:366)
java.net.URLClassLoader $ 1.run(URLClassLoader.java :355)
在java.security.AccessController.doPrivileged(本机方法)
在java.net.URLClassLoader.findClass(URLClassLoader.java:354)
在java.lang.ClassLoader.loadClass (ClassLoader.java:423)
在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308)
在java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 11更多
Java结果:1

编辑No.2



现在我转移到maven,认为它会下载所有依赖的库。但现在它显示不同的错误。





编辑3



由于它显示了一些Firefox的问题我用Chrome替换了Firefox。
此时以前的错误被删除。但一个新的图片。请看这个。





编辑编号4





编辑5



现在我再次转到firefox,给定页面,但它卡住了。为什么?



以下是我收到的错误快照。



解决方案

我相信这个问题你现在看到的是由于你传递了driver.get(url1);



我想你的意思是传递给driver.get(url1) ; (不要引用引号)



要扩展一点,引发格式不正确的uri异常的原因是传入(url1)的uri不包含任何协议(http / https)。


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.

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.

Edit no. 4

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.

解决方案

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

这篇关于在Maven中添加Selenium-java-2.31.0库后,Java代码抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆