TestProject Forum

Validating data in an embedded PDF control

In the app I am recording, I have the ability to click a link and display a PDF document within a container in the Chrome browser. I would like to validate strings contained within this document.

In reviewing the PDF Actions add-on, the actions associated with the add-on only seem to work when the PDF file saved locally. Is there any way to use this add-on (or a different one) to read and validate strings within the embedded PDF container instead? If so, can someone provide an example of how I can achieve this?


As you can see page with a preview of PDF doesn’t contain any HTML (elements) selenium uses elements in order to retrieve information from the DOM, if the page doesn’t contain any you cannot interact with it, the other addon utilize the PDF file itself, so downloading is the way to go if you need to verify the PDF file.

Hi Amit,

Along these lines, I have a similar scenario in my project wherein clicking a link in my web application opens a new URL ending with .pdf. Although I can verify the PDF URL from the DOM & the content by using add-on, I was just wondering why testproject recorder cannot interact with the PDF webpage, while my regular selenium WebDriver can. With my Selenium setup, I am able to switch the window and then fetch the PDF URL & validate it on the new PDF web page and then switch back to parent.

Not that I am blocked here, but was just curious why this difference in behavior of the WebDriver.

Hi Amit, how can I download pdf from preview pdf. I tried some solutions such as:

  • Ctrl + S, but can not send key by “S”
  • Can not find an element for the download button, too
  • Execute context-click but can not select “Save as…” by text or coordinator
    Could you please consult the way?
    Have a nice weekend.

Hi @nghia.vo,
'Ctrl+S', and other related send keys actions, only work in the context of your application.
So if your application contains an event listener for 'Ctrl+S' you will be able to use the send keys for that purpose. You can test it on websites like this: https://en.key-test.ru/
Interacting with the PDF preview page is not working for you because the context is Chrome browser which is a native Windows or macOS application.

1 Like

Hey @premangshu,
Regarding this case, you should be able to switch to the window and be able to get the URL as well.


It works as expected:

Simply created it from a normal tab.

Let me know if you have any questions

Hi Amit, I’m very glad to tell you that I just found a solution for myself.
I’m using action Execute JavaScript with this JS script:

var link = document.createElement('a');
link.href = url;//replace url with your url such as link.href = 'https://abc.com';
link.download = 'file.pdf';
link.dispatchEvent(new MouseEvent('click'));

I referred from this javascript - How to download PDF automatically using js? - Stack Overflow
From now, I can validate pdf data. For those who are stuck at this, hope my solution finds you well :smiley:

Thanks for sharing this important find, @nghia.vo,
Glad everything worked out. :slight_smile:

1 Like