Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6792213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:56:30+00:00 2026-05-26T17:56:30+00:00

My web application loads a pdf in the browser. I have figured out how

  • 0

My web application loads a pdf in the browser. I have figured out how to check that the pdf has loaded correctly using:

verifyAttribute
xpath=//embed/@src
{URL of PDF goes here}

It would be really nice to be able to check the contents of the pdf with Selenium – for example verify that some text is present. Is there any way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:56:31+00:00Added an answer on May 26, 2026 at 5:56 pm

    While not natively supported, I have found a couple ways using the java driver. One way is to have the pdf open in your browser (having adobe acrobat installed) and then use keyboard shortcut keys to select all text (CTRL+A), then copy it to the clipboard (CTRL+C) and then you can verify the text in the clipboard. eg:

    protected String getLastWindow() {
        return session().getEval("var windowId; for(var x in selenium.browserbot.openedWindows ){windowId=x;} ");
    }
    
    @Test
    public void testTextInPDF() {
        session().click("link=View PDF");
        String popupName = getLastWindow();
        session().waitForPopUp(popupName, PAGE_LOAD_TIMEOUT);
        session().selectWindow(popupName);
    
        session().windowMaximize();
        session().windowFocus();
        Thread.sleep(3000);
    
        session().keyDownNative("17"); // Stands for CTRL key
        session().keyPressNative("65"); // Stands for A "ascii code for A"
        session().keyUpNative("17"); //Releases CTRL key
        Thread.sleep(1000);
    
        session().keyDownNative("17"); // Stands for CTRL key
        session().keyPressNative("67"); // Stands for C "ascii code for C"
        session().keyUpNative("17"); //Releases CTRL key
    
        TextTransfer textTransfer = new TextTransfer();
        assertTrue(textTransfer.getClipboardContents().contains("Some text in my pdf"));
    }
    

    Another way, still in java, is to download the pdf and then convert the pdf to text with PDFBox, see http://www.prasannatech.net/2009/01/convert-pdf-text-parser-java-api-pdfbox.html for an example on how to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that has a page that loads the content from
I have a web application that dynamically loads assemblies based on database configuration entries
I'm creating a web application which loads tabs using AJAX. My problem is that
I wrote a WSGI compatible web application using web.py that loads a few dozen
I have a web application that loads some 50 tables from SQL Server into
I have a web application that loads javascript on page load: $(function() { $('.modal-delete').click(function()
I have a flash (flex) web application and when it first loads the cursos
I have a web application that can load plugins through reflection. It currently uses
I have an application that loads different documents to the server, and allows users
I have an ASP.Net 4.0 web application which very frequently loads data from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.