Selenium WebDriver Read PDF Content

In test automation activities, we may encounter scenario when we have to verify PDF content. In such scenarios, we have to use Java to read PDF files. In this post, we will see how we can use Selenium with Java to verify PDF content. Read on to find out more about Selenium WebDriver read PDF scenario.

Selenium WebDriver Read PDF Content

Selenium WebDriver Read PDF Content

We will use PDFBox API to read PDF file using Java code. For our example, we will read content of PDF file at this location and verify that it contains certain text.

Steps:

  • Download PDFBox API from here.
  • Reference PDFBox JAR file in your Selenium project.
  • Open your class file and define the URL of PDF file using this code.
  • Now, use below code to convert PDF content to text. PDFBox API is used along with Java input stream for this purpose.
  • Use TestNG assert command to verify that PDF contains ‘Open the setting.xml, you can see it is like this’ text.
  • After performing all above steps, your Selenium WebDriver read PDF method should be as below.

As you can see from above tutorial, reading PDF content is possible using Selenium WebDriver. Let us know how it goes for you.

Comments
  1. Andrei Solntsev
  2. santosh
  3. Ankit

Leave a Reply

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