How to change the browser default download directory

Browsers have a default directory where downloaded files are stored. When your automation includes steps where the web browser initiates the download of files (for example clicking on a button), you will probably want to specify your own target directory for downloads. This allows the robot to reach the downloaded files and use them in the next steps of the process.

The following robot downloads a file to a custom browser download directory:

Selenium (RPA.Browser.Selenium)

*** Settings *** Documentation Download a file to a custom browser download directory. Library RPA.Browser.Selenium Library OperatingSystem *** Variables *** ${FILENAME}= file-sample_150kB.pdf ${DOWNLOAD_DIR}= ${CURDIR} *** Tasks *** Download a file to a custom browser download directory Set Download Directory ${DOWNLOAD_DIR} Open Available Browser ... https://file-examples.com/index.php/sample-documents-download/sample-pdf-download/ Click Link css:.download-button Wait For Download To Complete [Teardown] Close All Browsers *** Keywords *** Wait For Download To Complete Wait Until Keyword Succeeds ... 2 min ... 5 sec ... File Should Exist ... ${FILENAME}

Before opening the browser using the Open Available Browser keyword, we add the Set Download Directory keyword, passing it the directory where we want the files to be saved. In this case, we want the robot to download to the current directory (${CURDIR}).

Playwright (RPA.Browser.Playwright)

*** Settings *** Documentation Download a file to a custom browser download directory. Library RPA.Browser.Playwright *** Variables *** ${FILENAME}= file-sample_150kB.pdf ${DOWNLOAD_DIR}= ${CURDIR} *** Tasks *** Download a file to a custom browser download directory New Context acceptDownloads=${True} New Page ... https://file-examples.com/index.php/sample-documents-download/sample-pdf-download/ ${download_promise}= ... Promise To Wait For Download ... ${DOWNLOAD_DIR}${/}${FILENAME} Click css=.download-button Wait For ${download_promise}
Last edit: May 5, 2022