• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

  • Home
  • Interview Questions
  • Java
  • Java Programs
  • Selenium
  • Selenium Programs
  • Manual Testing
  • Test Cases
  • Difference
  • Tools
  • SQL
  • Contact Us
  • Search
SoftwareTestingo » Selenium » Selenium Programs » How to Verify PPT Text using Apache POI in java Selenium Program?

How to Verify PPT Text using Apache POI in java Selenium Program?

Last Updated on: March 14, 2019 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • Verify PPT Text Example Program

Verify PPT Text Example Program

How to Verify PPT Text using Apache POI in java Selenium Program?

Program: Highlight Selected Field In Selenium

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()&amp;&amp; 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);
         }
      }
   }	 
}	
}
Read Also: Automate Real-Time Scenario Using Java Selenium

    Filed Under: Selenium Programs

    Reader Interactions

    Comments

    1. Avatar for vamsivamsi says

      September 3, 2018 at 10:14 PM

      test

      Reply

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Categories

    Copyright © 2022 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy ~ Testing Careers