Using Selenium is it possible to verify if text is present inside a PDF which is loaded by the browser

0 votes

My application opens a PDF in the browser. I can check if the PDF was loaded with this:

verifyAttribute xpath=//embed/@src {PDF's URL}

My test would be complete if I can also check the contents of the PDF with Selenium itself. I need to check if some text is present. Is this even possibe with Selenium?

Apr 18, 2018 in Selenium by kappa3010
• 2,090 points
16,747 views

1 answer to this question.

0 votes

Reading PDF contents is not a functionality which is natively supported by WebDriver. However, PDFBox API can be used read the content of a PDF file. The only thing to remember is, you have to shift the focus of browser window to the opened PDF. Post this, you can parse the contents of your PDF and then search for any text string.

Sample code for using PDFBox API within Selenium is below. It worked for me. You can download the JAR from here: https://pdfbox.apache.org/index.html

public void ReadPDF() throws Exception
{
//For defining the URL of PDF
URL TestURL = new URL("http://www.axmag.com/download/pdfurl-guide.pdf");

// For converting content inside PDF to text & using PDFBox API with java input stream for parsing
BufferedInputStream TestFile = new BufferedInputStream(TestURL.openStream());
PDFParser TestPDF = new PDFParser(TestFile);
TestPDF.parse();
String TestText = new PDFTextStripper().getText(TestPDF.getPDDocument());

// Use TestNG assertion for checking if your text is present in content
Assert.assertTrue(TestText.contains("Open the setting.xml, you can see it is like this")); 
}
answered Apr 18, 2018 by king_kenny
• 3,710 points
Using Selenium  is it possible to verify if text is present inside a PDF which is loaded by the browser  | Edureka Community
[url=http://www.gd8h51hvu26619731d31hr873wpalwdss.org/]umwzdsdfnri[/url]
mwzdsdfnri http://www.gd8h51hvu26619731d31hr873wpalwdss.org/
<a href="http://www.gd8h51hvu26619731d31hr873wpalwdss.org/">amwzdsdfnri</a>

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

Is it possible for a website to detect that we are using Selenium with ChromeDriver

Selenium tests for pre-defined javascript variables which ...READ MORE

answered Apr 28, 2018 in Selenium by Meci Matt
• 9,460 points
5,833 views
+1 vote
2 answers

Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

I using next code for facebook for ...READ MORE

answered May 16, 2019 in Selenium by mslavikas@gmail.com
25,546 views
0 votes
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,577 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,559 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,606 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,506 views
+1 vote
2 answers

Is it possible to manually set the attribute value of a Web Element using Selenium?

WebDriver driver; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.getElementById('id123').setAttribute('attr', ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
26,639 views
+1 vote
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP