Verify PPT Text Example Program
How to Verify PPT Text using Apache POI in java Selenium Program?
Below Code Giving: invocation target exception,
public boolean verifyTextonPPT(String object,String data)throws InterruptedException, Exception { String[] arrTempData = data.split("\\|"); int intSlideCount = 0; int intSlideNo = 0; String strSlideTitle = ""; boolean blnFlag = true; try { //String[] arrTempData = data.split("\\|"); arrTempData[0] = getRunTimeVariable("GetLastDownloadedFile"); HSLFSlideShow ppt = new HSLFSlideShow(new FileInputStream(DriverClearForceTestScript.downloadPath + "\\" + arrTempData[0])); intSlideCount++; for (HSLFSlide slide : ppt.getSlides()) { for (HSLFShape shape : slide.getShapes()) { // name of the shape String name = shape.getShapeName(); if (shape instanceof HSLFTextShape) { HSLFTextShape txShape = (HSLFTextShape) shape; for (HSLFTextParagraph xslfParagraph : txShape.getTextParagraphs()) { System.out.println(xslfParagraph.getTextRuns()); List<HSLFTextRun> originalText = xslfParagraph.getTextRuns(); if (!arrTempData[1].trim().isEmpty()&& originalText.contains(arrTempData[1].trim())) { intSlideNo=slide.getSlideNumber(); System.out.println("Slide Number for " +arrTempData[1]+"is:"+ intSlideNo ); String title = slide.getTitle(); System.out.println("Slide Title for " +arrTempData[1]+"is:"+ title ); blnFlag = true; break; } } } } if (blnFlag) { System.out.println("The String"+ arrTempData[1].trim() + " is Available in slide No:" +intSlideNo); APP_LOGS.debug("The String"+ arrTempData[1].trim() + " is Available in slide No:" +intSlideNo); return true; } else { System.out.println("The String " + arrTempData[1].trim() + " is not Available in " + intSlideNo); APP_LOGS.debug("The String " + arrTempData[1].trim() + " is not Available in " + intSlideNo); return false; } } } catch (Exception e) { keyerrormsg=e.getMessage().split("\n")[0].split("<")[0]; APP_LOGS.info(keyerrormsg); return false; } return blnFlag; }
Working Code:
public static void main(String[] args) throws IOException { String fileName="D:\\1.pptx"; FileInputStream inputStream; try { inputStream = new FileInputStream(fileName); } catch (FileNotFoundException e) { e.printStackTrace(); return; } XMLSlideShow ppt; try { ppt = new XMLSlideShow(inputStream); } catch (IOException e) { e.printStackTrace(); return; } readPPT(ppt); } public static void readPPT(XMLSlideShow ppt) { CoreProperties props = ppt.getProperties().getCoreProperties(); String title = props.getTitle(); System.out.println("Title: " + title); for (XSLFSlide slide: ppt.getSlides()) { System.out.println("Starting slide..."); List<XSLFShape> shapes = slide.getShapes(); for (XSLFShape shape: shapes) { if (shape instanceof XSLFTextShape) { XSLFTextShape textShape = (XSLFTextShape)shape; String text = textShape.getText(); System.out.println("Text: " + text); } } } } }
test