how to resolve htmlUnit WrapsDriver Error - java

I'm running test with HtmlUnit with selenium 3.13 jar, browser launches successfully, but after than it stops working with below error.
> Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/WrapsDriver
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.toWebElement(HtmlUnitDriver.java:1211)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByName(HtmlUnitDriver.java:1341)
at org.openqa.selenium.By$ByName.findElement(By.java:284)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$4.call(HtmlUnitDriver.java:2024)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$4.call(HtmlUnitDriver.java:2020)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1660)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:2020)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:798)
at com.directlegalmail.startup.Startup.scrapDates(Startup.java:89)
at com.directlegalmail.startup.Startup.main(Startup.java:63)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WrapsDriver
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 22 more
does anyone knows how to resolve it, I have
selenium 3.13
and htmlUnit Driver 2.33
below is my code
driver = new HtmlUnitDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait
(10000,TimeUnit.MILLISECONDS);
logMsg("Browser launched successfully");
driver.get("WebURL");

you need to use htmlUnit Driver with dependencies, download the latest htmlunit-driver-x.xx.x-jar-with-dependencies.jar from github which include WrapsDriver class.

Some more information about your Test Environment would have given us some more idea what exactly going wrong.
However I don't see any major issues in your code block. With Selenium v3.14 and HtmlunitDriver v2.33.0 while invoking HtmlUnitDriver you need to pass the argument true to enable JavaScript and you can use the following solution:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class A_HtmlunitDriver_2_33_0 {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new HtmlUnitDriver(true);
driver.manage().window().maximize();
driver.get("https://stackoverflow.com/questions/53812207/how-to-resolve-htmlunit-wrapsdriver-error");
System.out.println("HtmlUnitDriver invoked");
driver.quit();
}
}

This combination of dependencies worked for me:
implementation("org.seleniumhq.selenium:selenium-java:3.141.59")
implementation("org.seleniumhq.selenium:selenium-api:3.141.59")
implementation("org.seleniumhq.selenium:htmlunit-driver:2.36.0")
You can see the compatible Selenium dependencies for HtmlUnit Driver version 2.36.0 here: https://github.com/SeleniumHQ/htmlunit-driver/blob/2.36.0/pom.xml

Related

Error message in simple selenium code

I'm trying to learn selenium. So I installed the below tools:
Firefox V 31
Selenium-firefox-driver-2.0b3
And I used the code below to run it and got a error message. Not sure what it means. Any help will be good.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Sele {
/**
* #param args
*/
public static void main(String[] args) {
// Create webDriver reference
WebDriver driver;
// Launch FirefoxDriver
driver = new FirefoxDriver();
// Open the web page
driver.get("http://google.com");
// Enter the text in the search box
WebElement searchText = driver.findElement(By.name("q"));
searchText.sendKeys("FirefoxDriver");
// Close the driver
driver.quit();
}
}
Error message :
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/RenderedWebElement
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at Sele.main(Sele.java:17)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.RenderedWebElement
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
It seem you have a dependency missing as explained on their main site you need to install the selenium server as well not just the browser driver.

ClassNotFoundException: org.apache.xerces.parsers.AbstractSAXParser when using boilerpipe

I am very new to boilerpipe and I am trying out the following basic code:
package contentExtraction;
import java.net.URL;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
public class ContentExtractor {
public static void main(String[] args) throws Exception {
final URL url = new URL(
// "http://www.l3s.de/web/page11g.do?sp=page11g&link=ln104g&stu1g.LanguageISOCtxParam=en"
"http://www.dn.se/nyheter/vetenskap/annu-godare-choklad-med-hjalp-av-dna-teknik"
);
System.out.println(ArticleExtractor.INSTANCE.getText(url));
}
}
But I am getting the following error when trying to run the above piece of code:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractSAXParser
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at de.l3s.boilerpipe.sax.BoilerpipeSAXInput.getTextDocument(BoilerpipeSAXInput.java:51)
at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:69)
at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:87)
at contentExtraction.ContentExtractor.main(ContentExtractor.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.AbstractSAXParser
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 16 more
I googled the error and came across this link. I thought that I was missing xercesImpl.jar in my dependencies. I included the same, still my code is giving the same error. What is the issue?
I figured the solution myself. The boilerpipe jar has further dependencies. I converted my project to maven project, included the dependency:
<dependency>
<groupId>com.syncthemall</groupId>
<artifactId>boilerpipe</artifactId>
<version>1.2.1</version>
</dependency>
When I build the above project, I can see there are actually 4 jars that are imported in Maven Dependencies folder:
boilerpipe-1.2.1.jar
nekohtml-1.9.18.jar
xercesImpl-2.11.0.jar
xml-apis-1.4.01.jar

REST Assured: missing class that's (apparently) not missing

Here's my simple code:
import static com.jayway.restassured.RestAssured.get;
public class testget {
public static void main(String[] args) {
Response countryName = get("http://maps.googleapis.com/maps/api/geocode/json?latlng=45.2542285874,30.2564857&sensor=false");
System.out.println(countryName);
System.exit(0);
}
}
When running, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/jayway/restassured/mapper/factory/ObjectMapperFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.jayway.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
at com.jayway.restassured.RestAssured.<clinit>(RestAssured.java:423)
at testeget.main(testeget.java:6)
Caused by: java.lang.ClassNotFoundException: com.jayway.restassured.mapper.factory.ObjectMapperFactory
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
But the Rest Assured lib is loaded, otherwise the get method wouldn't even be called... What could it be?
I'm using Rest Assured 2.8.
Update:
I'm using Eclipse to run it, and the classpath has, besides the default Java/Eclipse content, the path to the .jar file of Rest Assured and it's dependencies, as listed on their website.
Dependencies list on the bottom of the page (all added to the classpath).
http://mvnrepository.com/artifact/com.jayway.restassured/rest-assured/2.8.0

noclassdeffounderror in a simple networking program. I am using Eclipse IDE to run java programs

import java.net.InetAddress;
import java.net.UnknownHostException;
class IpAddr {
public static void main(String arg[]) {
System.out.println("Hello Jagadeesh...>!!");
try {
InetAddress ia=InetAddress.getByName("www.facebook.com");
System.out.println(ia);
}
catch(UnknownHostException uhe) {
System.out.println("ip address of facebook is not found. :(");
}
}
}
In console: while running
E:\myworkspace\network_practice\src\stage1>javac IpAddr.java
E:\myworkspace\network_practice\src\stage1>java IpAddr
Exception in thread "main" java.lang.NoClassDefFoundError: IpAddr (wrong name: s
tage1/IpAddr)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
E:\myworkspace\network_practice\src\stage1>cd..
You did not declare a package in your class so it goes to default package.But you have stage1 folder.
NoClassDefFoundError in Java comes when Java Virtual Machine is not
able to find a particular class at runtime which was available during
compile time.
Source: http://javarevisited.blogspot.de/2011/06/noclassdeffounderror-exception-in.html
Therefore I would check if you have added everything neccessary to your class path.
Jagadeesh,
it might be the case that your InetAddress jar version might not be supported

String encryption with Jasypt library

I want to encrypt a string, but the standard Java libraries are too complicated for me.
So I turned to Jasypt labriry. It's pretty simple to use and understan. However when I import the library to Eclipse 3.6 and when I try encrypt a string like "Hello" with the password "123", it always comes up with an error. I'm not sure what I'mm doing wrong but I think it also happens when I use other libraries in Eclipse.
Source:
import org.jasypt.util.text.BasicTextEncryptor;
public class Main {
static BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
public static void main(String[] args) {
System.out.println("Hello World");
textEncryptor.setPassword("123");
System.out.println(textEncryptor.encrypt("Hello World"));
}
}
The error message:
java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.jasypt.util.text.BasicTextEncryptor.<init>(BasicTextEncryptor.java:67)
at eMain.<clinit>(eMain.java:4)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 14 more
The library you imported depends on another library containing org/apache/commons/lang/exception/NestableRuntimeException. This is located in the Apache Commons Lang library.
In fact, if you downloaded JASYPT from http://sourceforge.net/projects/jasypt/files/ you'll get a zip file containing a lib-folder with these files:
commons-codec-1.1.jar
commons-lang-2.1.jar
jasypt-1.6.jar
You should include all of these in your project.
I tried it and your little sample program works fine (and prints the following)
Hello World
v09l9j/BIeSoMkQXc2CY0VIJLlLAQTYq

Categories

Resources