Print to PDF Question

For starters: I read a lot of other posts regarding this issue, but wanted to ask if there is any updated solutions.
I already read this:How to click on download of pdf and save inside browser windw in robot framrwork

So I have a print form to a pdf button, and want to save that pdf for further comparisons in the same testcase.

Is there a way to use Browser keywords, such as “Promise to wait for download” to download pdf to current directory?
I have tried many ways without succeeding, the problem being that “save file as” is not part of the browser context. I can get to the stage where pressing print would get me to “save file as” part when manually doing the steps.

Also as the pdf is generated at that instance, there is no direct url to file

-Thanks

Hello,

Been there too, where I needed to check pdf content, and also get a screenshot of the content.
From my understanding and search in ways to interact with the PDF viewer, main issue is that buttons (i.e. the print/download one) are in shadow-dom and not easily interactable.

On my side I finally choose to do this :

  1. Start browser (Chrome here) with options to directly download the file
  2. Check content with PyPDF2 and a .py file
  3. Eventually , as the PDF is directly downloaded and not displayed , open it to perform the required screenshot. Note here that it’s OK while your content his in first page

Challenging thing then is if you need to scroll down the pdf for visual checks.

Regards.

2 Likes

How do you directly download the pdf?
That has been my issue, cant seem to be able to get that file for comparison.
In my case there is no one file to download, so I could use that Download -keyword properly.

And yes, I use chrome also
-Joel

Hi,

It’s not a keyword it’s chrome startup option. Found several issues on forums and all, but finally this worked for me :

${browser_prefs}    Create Dictionary     download.default_directory=_yourfolder      plugins.always_open_pdf_externally=${True}
${chrome_options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
Call Method    ${chrome_options}    add_argument    --log-level\=3
Call Method    ${chrome_options}    add_experimental_option    prefs    ${browser_prefs}

Then Open Browser with options :

  Open Browser    url   chrome    options=${chrome_options}
  • Note : The -log-level is not necessary, it’s just an example if you have to add other arguments/options (gpu, sandbox…) to your ${chrome_options}.
  • Note : for yourfolder, depending of your OS you could use ${/} for path (have it working on Windows and Linux for example)

This will the PDF downloaded where it should normally open in a new tab.

Best Regards.

Charlie

2 Likes