Downloading the Excel file

Each week, the actual sales data is exported from the company's sales system 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 sales representative. But first, it needs to download the Excel file.

As always, we add one more line (a keyword call) 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 add a new keyword to the *** Keywords *** section:

*** Keywords ***
Download the Excel file

Great! Now we have to implement the keyword.

Adding the RPA.HTTP library

Currently, our robot does not know how to download files from remote web servers. But by now, we know how to teach an old robot new skills: by adding a library!

Our trusty rpaframework set of open-source automation 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 library import line to our *** Settings *** section like this:

*** Settings ***
Documentation     Insert the sales data for the week and export it as a PDF.
Library           RPA.Browser.Selenium    auto_close=${FALSE}
Library           RPA.HTTP

The auto-completion works with library imports, too: Try typing li and auto-completing the rest.

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

The Download keyword requires a URL as an argument. 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 argument to True. This way, we can count on the local file being always the most recent version (if the file exists, the robot has our permission to overwrite it).

Our keyword becomes:

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

With these additions, our robot looks like this:

*** Settings ***
Documentation     Insert the sales data for the week and export it as a PDF.
Library           RPA.Browser.Selenium    auto_close=${FALSE}
Library           RPA.HTTP

*** 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

*** Keywords ***
Open the intranet website
    Open Available Browser    https://robotsparebinindustries.com/

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

Download the Excel file
    Download    https://robotsparebinindustries.com/SalesData.xlsx    overwrite=True

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

Let's run our robot now (Shift-Command-P (macOS) or Ctrl+Shift+P (Windows)).

Great! Our robot has downloaded the remote file (SalesData.xlsx). You should find the file amongst your other robot files. You could instruct the robot to download to a different location, but we are okay with the current working directory.

What we learned

  • You can use the RPA.HTTP library, part of the rpaframework collection of open-source automation libraries, 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 overwrite an existing file of the same name if found.
  • The robot still looks human-readable'ish!