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,


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