• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.NoClassDefFoundError: org/dom4j/DocumentException - error encontered

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting the following error while trying to open an excel file using Junit4 selenium web driver in Eclipse. Code and error is pasted below. I am new to Java. Please help. Thank you.

Error message in ecliplse
java.lang.NoClassDefFoundError: org/dom4j/DocumentException
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:154)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
at org.apache.poi.openxml4j.opc.Package.<init>(Package.java:54)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:82)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:228)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:187)
at clsUSPSMatch_WebDeriver.xlRead_TC(clsUSPSMatch_WebDeriver.java:203)
at clsUSPSMatch_WebDeriver.setUp(clsUSPSMatch_WebDeriver.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

Code

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.WebDriver;

//import statement for excel files - VD Nov/224/2012
//import org.apache.poi.ss.usermodel.*;
//import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.* ;
import org.apache.poi.xssf.usermodel.*;

/*
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
*/

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;




public class clsUSPSMatch_WebDeriver {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();


int xRows_Inp, xCols_Inp;
String xData_Inp[][];

@Before
public void setUp() throws Exception {

System.out.println("Step1- Starting the browser --> Reached");
driver = new InternetExplorerDriver();
//driver = new FirefoxDriver();
baseUrl = "https://www.usps.com/";

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//driver.manage().window().setSize();

//Procedure to read from an excel file -vd
xlRead_TC("C:\\USPS\\USPSInput.xlsx", 0);


}

@Test
public void testUntitled() throws Exception {

//Declare Global Input Variables -Vivek D
String vRecord, vAddrInp, vCityInp, vZipInp; //

//int xRows_Inp, xCols_Inp;
//String xData_Inp[][];

//Declare Global Output Variables -Vivek D
String vAddr1, vCity1, vAddr2, vCity2,vAddr3, vCity3; //
String vAddr1Pdm, vCity1Pdm, vAddr2Pdm, vCity2Pdm, vAddr3Pdm, vCity3Pdm;

int counter;

// open | https://www.usps.com/ |
driver.get("https://www.usps.com/");
System.out.println("Step2- Opening the browser --> Reached");
// assertTitle | USPS - The United States Postal Service (U.S. Postal Service) |
assertEquals("USPS - The United States Postal Service (U.S. Postal Service)", driver.getTitle());


// click | id=qt-zip-link |
//driver.findElement(By.xpath("qt-zip-link")).click();
Thread.sleep(30000);

//For loop to go tjrough the logic 3 times
for (counter = 0; counter < 2; counter ++){
Thread.sleep(20000);
System.out.println("Counter valie is :" + counter);
driver.findElement(By.id("qt-zip-link")).click();
//driver.findElement(By.linkText("Look Up A ZIP Code")).click();

Thread.sleep(30000);
System.out.println("Step3- clicked the look up a zip code button --> Reached");

// type | id=qz-tAddress | 1000 aviara parkway
driver.findElement(By.id("qz-tAddress")).clear();
driver.findElement(By.id("qz-tAddress")).sendKeys("1000 aviara parkway");
// type | id=qz-tCity | carlsbad
driver.findElement(By.id("qz-tCity")).clear();
driver.findElement(By.id("qz-tCity")).sendKeys("carlsbad");
// click | css=span.select-current-text |
driver.findElement(By.cssSelector("span.select-current-text")).click();
// click | link=CA - California |
driver.findElement(By.linkText("CA - California")).click();
// type | id=qz-tZip | 92009
driver.findElement(By.id("qz-tZip")).clear();
driver.findElement(By.id("qz-tZip")).sendKeys("92009");
Thread.sleep(3000);
// click | id=dofind_btn |
driver.findElement(By.id("dofind_btn")).click();
System.out.println("Step4- clicked the find addresses button --> Reached");

//copy the results to output variables
Thread.sleep(3000);
System.out.println("Step5- copy the addresses to output variables --> Reached");

//writing the results to variables - first set
//Initialize Global Output Variables - Vivek D
vAddr1 = ""; vCity1=""; vAddr2=""; vCity2=""; vAddr3=""; vCity3=""; //
vAddr1Pdm = ""; vCity1Pdm = ""; vAddr2Pdm = ""; vCity2Pdm = ""; vAddr3Pdm = ""; vCity3Pdm = ""; //

System.out.println(" The retrieved address1 before: " + vAddr1);
vAddr1 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div/div[3]")).getText();
//vAddr1 = selenium.getText("xpath=html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div/div[3]");
System.out.println(" The retrieved address1 after: " + vAddr1);

System.out.println(" The retrieved city1 before: " + vCity1);
vCity1 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div/div[4]")).getText();
System.out.println(" The retrieved city1 after: " + vCity1);

//writing the results to variables - second set
System.out.println(" The retrieved address2 before: " + vAddr2);
vAddr2 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div[2]/div[3]")).getText();
System.out.println(" The retrieved address2 after: " + vAddr2);

System.out.println(" The retrieved city2 before: " + vCity2);
vCity2 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div[2]/div[4]")).getText();
System.out.println(" The retrieved city2 after: " + vCity2);

//writing the results to variables - third set
System.out.println(" The retrieved address3 before" + vAddr3);
vAddr3 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div[3]/div[3]")).getText();
System.out.println(" The retrieved address3 after" + vAddr2);

System.out.println(" The retrieved city3 before" + vCity3);
vCity3 = driver.findElement(By.xpath("html/body/div[2]/div[2]/div/div/div/div/form[2]/div[2]/div[3]/div[2]/div/div[3]/div[4]")).getText();
System.out.println(" The retrieved city3 after" + vCity3);

//Close the look up window
// click | id=qtmodal-box-closeModal |
driver.findElement(By.id("qtmodal-box-closeModal")).click();
} // end for loop - vivek D
}

@After
public void tearDown() throws Exception {
//driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}

private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}

public void xlRead_TC(String sPath, int sSheet) throws Exception{
//XSSFWorkbook wb = new XSSFWorkbook();
//XSSFWorkbook workBook = new XSSFWorkbook(destDir);
//Workbook wb = new XSSFWorkbook();
//FileOutputStream f = new FileOutputStream("C:\\USPS\\USPSInput.xlsx",true);
//File inputWorkbook = new File("C:\\USPS\\USPSInput.xlsx");
//Workbook w;
//w = Workbook.getWorkbook(inputWorkbook);


//Workbook book = Workbook.createWorkbook(f);

System.out.println("Step 1B - Opening excel files Reached");
File myxl = new File(sPath);
FileInputStream myStream = new FileInputStream(myxl);
//Workbook w;
//w = Workbook.getWorkbook(myStream);

XSSFWorkbook myWB = new XSSFWorkbook(myStream);
//XSSFSheet mySheet = myWB.getSheetAt(sSheet); // Referring to 1st sheet

//xRows_Inp = mySheet.getLastRowNum()+1;
//xCols_Inp = mySheet.getRow(0).getLastCellNum();
System.out.println("Rows are " + xRows_Inp);
System.out.println("Cols are " + xCols_Inp);


//Workbook[] wbs = new Workbook[] { new HSSFWorkbook(), new XSSFWorkbook() };

//xRows_TC = mySheet.getLastRowNum()+1;
//xCols_TC = mySheet.getRow(0).getLastCellNum();
//System.out.println("Rows are " + xRows_TC);
//System.out.println("Cols are " + xCols_TC);
//xData_TC = new String[xRows_TC][xCols_TC];
}//
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's because POI needs to have the DOM4J jar in the classpath. You'll find it in your POI download in the ooxml-lib folder.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This http://www.compiletimeerror.com/2013/06/javalangnoclassdeffounderror_7.html will help you out.. Have a look..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic