Downloading the Excel file

Like our Process Definition Document tells us, the "real" sales data is exported from the company's sales system each week, and uploaded to the intranet. Our robot will need to get the data out of the Excel file and fill the sales form for each of the sales representatives. But first, it needs to download it locally.

So, as always, we want to add one more line to our *** Tasks *** section. This time we will not add it at the end of the task, but before the Fill And Submit The Form keyword:

*** Tasks ***
Insert the sales data for the week and export it as a PDF
    Open The Intranet Website
    Log In
    Download The Excel File
    Fill And Submit The Form

Then, as you probably guessed by now, we need to add a new *** Keywords *** cell before the *** Tasks *** one with our new keyword:

*** Keywords ***
Download The Excel file

Great! Now we have to implement the keyword.

Adding the RPA.HTTP library

Our robot at the moment does not know how to download files from remote web servers, but by now, we know how we can teach an old robot new skills: by adding a library!

Our trusty rpaframework set of libraries includes the RPA.HTTP library that adds many keywords to work with remote web servers, so that's just what we need.

We add a new line to our *** Settings *** section like this:

*** Settings ***
Documentation     Robot to enter weekly sales data into the RobotSpareBin Industries Intranet.
Library           RPA.Browser
Library           RPA.HTTP

Now we can use all of the keywords contained in the RPA.HTTP, including the Download keyword.

The Download keyword requires a URL as an argument, and we know that we can expect our Excel file at https://robotsparebinindustries.com/SalesData.xlsx each week.

In addition to the URL argument, we are also setting the overwrite parameter to TRUE, so that we can count on the local file being always the most recent version.

So our keyword becomes:

*** Keywords ***
Download The Excel file
    Download    https://robotsparebinindustries.com/SalesData.xlsx    overwrite=True

With these additions, now our robot looks like this:

*** Settings ***
Documentation     Robot to enter weekly sales data into the RobotSpareBin Industries Intranet.
Library           RPA.Browser
Library           RPA.HTTP

*** Keywords ***
Open The Intranet Website
    Open Available Browser    https://robotsparebinindustries.com/

*** Keywords ***
Log In
    Input Text    id:username    maria
    Input Password    password    thoushallnotpass
    Submit Form
    Wait Until Page Contains Element    id:sales-form

*** Keywords ***
Fill And Submit The Form
    Input Text    firstname    John
    Input Text    lastname    Smith
    Input Text    salesresult    123
    Select From List By Value    salestarget    10000
    Click Button    Submit

*** Keywords ***
Download The Excel file
    Download    https://robotsparebinindustries.com/SalesData.xlsx    overwrite=True

*** Tasks ***
Insert the sales data for the week and export it as a PDF
    Open The Intranet Website
    Log In
    Download The Excel File
    Fill And Submit The Form

Let's run our robot now, clicking on the >> button:

Downloading the Excel file

Great! Our robot has downloaded the remote file, and put it alongside our tasks.robot script:

Excel file in file viewer

What we learned

  • You can use the RPA.HTTP library, part of the rpaframework, to interact with remote webservers.
  • You can use the Download keyword to easily download remote files to your local computer.
  • The Download keyword can be configured to always overwrite an existing file of the same name, if found.