Disable Chrome PDF Viewer option not working in robot framework

I have scenario when I click on Submit , it open the PDF in the window i.e. in chrome pdf viewer and I want to download that pdf in the download directory path instead opening that in the new page

I tried below code -

${download_directory}    Join Path    ${OUTPUT DIR}    downloads
Set Global Variable    ${download_directory_guid}  downloads
Create Directory    ${download_directory}
Set Global Variable    ${download_directory}

${chrome options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
# list of plugins to disable. disabling PDF Viewer is necessary so that PDFs are saved rather than displayed
${disabled}    Create List    Chrome PDF Viewer

${prefs} Create Dictionary download.default_directory ${download_directory} plugins.always_open_pdf_externally ${True}

${prefs}    Create Dictionary    download.default_directory=${download_directory}    plugins.plugins_disabled=${disabled}
Call Method    ${chrome options}    add_experimental_option    prefs    ${prefs}
Call Method    ${chrome_options}   add_argument    no-sandbox
Create Webdriver    Chrome    chrome_options=${chrome options}
maximize browser window
Go To    http://mysite.com

I have tried with option plugins.always_open_pdf_externally ${True} and ${False}
Also tried this option -plugins.plugins_disabled=${disabled}

But pdf is still opened in chrome viewer.

Hi @bk-user,

I’ll suggest trying to approach from a different angle, rather than trying to disable the pdf viewer, why not try right click the link and save as?

Click Element has a modifier option you could add a control key to that and get a context menu, then potentially Press Keys to send a s and a RETURN

I’ve never done it either way just offering suggestions,

Dave.

try this:

    ${browser_prefs}    Create Dictionary     download.default_directory=${REPORTS_DIR}    plugins.always_open_pdf_externally=${True}
Open Browser    about:blank    ${BROWSER}    options=add_experimental_option("prefs",${browser_prefs})

This will automatically download the file to the given directory.

1 Like

Hi,

I have been using the pdf download solution, associated with a reopening of the file in case I need to capture visual proof.
Py2PDF is used to control Pdf content.

However opening with Chrome Viewer is still an issue, as interacting with the viewer page and its shadow-Dom is quite complicated.

For example in the case on a multi page Pdf with need to scroll to a specific locator/object present in document (i.e. a logo) I was wondering if there were some solutions, or other libraries that would do the job ?

I’m using also SikuliX library, so the main concern would be to scroll down to a specific part/paragraph in the case of a logo, then use SikuliX to get the target.

Thanks for your ideas !