How to download a file based on post request

I have a system that generate Excel reports based on a filled form.
How do I capture the file response so that I can continue working on the file.

“Download” takes an Url.

Hello @morten,

could give a bit more detail about your case and how your application works?

Is this all happening via an API, where you POST the form data and you get the file back as part of the response? is there a UI involved?

It’s a web application for time registration.

I’m navigating the application using RPA.Browser. I’ve successfully logged in and can get to the reporting view. Here I can setup a range of parameters eg. date span as well. Next step is to download the report in Excel so that I can work with it from here. To do that I can tricker the JavaScript “__doPostBack(‘btnSaveSearchView’,’’)” but that will not equal a download request and the file will not be available to further work on.

hi @morten !

I tried to simulate your situation like this:

  • instruct the browser to download an excel file (in this case it’s clicking on a link, but the assumption is that should be the same as receiving a file response
  • set the download location in browser settings, passing the configuration to Open Chrome Browser (this particular solution works in Chrome only)
  • ensure that the downloaded file exists, using Wait Until Keyword Succeeds and File Should Exist
  • open the downloaded file with the RPA.Excel.Files library and read its contents.

(To simplify the code, I am using the folder where the robot is running from, you will need to set the appropriate paths, probably)

Here’s the code:

*** Settings ***
Library           RPA.Browser
Library           RPA.Excel.Files
Library           OperatingSystem

*** Variables ***
${FILENAME}=      file_example_XLS_10.xls

*** Tasks ***
Download xls file via browser and process it
    ${prefs}=    Create Dictionary    download.default_directory=${DIRECTORY}
    Open Chrome Browser    preferences=${prefs}
    Click link
    Wait Until Keyword Succeeds    2 min    5 sec    File Should Exist    file_example_XLS_10.xls
    Open Workbook    file_example_XLS_10.xls
    ${table}=    Read Worksheet As Table    header=True
    Close Workbook
    FOR    ${row}    IN    @{table}
        Log    ${row}
    [Teardown]    Close All Browsers

Here’s how it looks like in Robocode Lab:

I hope this helps! :slight_smile: