Collecting the results

All the sales data has been entered. Nice! After entering all the sales data, Maria typically takes a screenshot of the sales summary:

Sales summary in the intranet page

Our robot can handle this case too!

Let's add a new step to our task. We'll call it Collect The Results:

*** 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 The Form Using The Data From The Excel File
    Collect The Results

Above the *** Tasks *** cell, we add a new keyword:

*** Keywords ***
Collect The Results

The RPA.Browser library provides the Capture Element Screenshot keyword to help us with this step. It takes a locator as an argument. Let's take a look at the HTML markup of the page to see if there is a locator we could use:

...
<div class="alert alert-dark sales-summary" role="alert">
  <div><span>Active sales people:</span>...</div>
</div>
...

How did we find that HTML markup? See the How to find user interface elements using locators in web applications article if you want to learn how to view the HTML markup of web pages using browser developer tools.

We have a div element. It has class and role attributes. Since there are no id or name attributes to work with, we decide to use the CSS classes to target it. The sales-summary class seems like a good candidate because then it will be clear in our script what we are taking a screenshot of. Because we are using CSS to locate the element, our locator will start with css:. There are multiple types of locators: id:, name:, xpath, depending on the strategy used.

Our keyword implementation becomes:

*** Keywords ***
Collect The Results
    Capture Element Screenshot    css:div.sales-summary

The css:div.sales-summary locator means:

Using the CSS strategy, find me a div element that has the sales-summary CSS class. With extra cheese. Grazie! Danke schön!

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.Excel.Files
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 For One Person
    [Arguments]    ${salesRep}
    Input Text    firstname    ${salesRep}[First Name]
    Input Text    lastname    ${salesRep}[Last Name]
    Input Text    salesresult    ${salesRep}[Sales]
    ${target_as_string}=    Convert To String    ${salesRep}[Sales Target]
    Select From List By Value    salestarget    ${target_as_string}
    Click Button    Submit

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

*** Keywords ***
Fill The Form Using The Data From The Excel File
    Open Workbook    SalesData.xlsx
    ${salesReps}=    Read Worksheet As Table    header=True
    Close Workbook
    FOR    ${salesRep}    IN    @{salesReps}
        Fill And Submit The Form For One Person    ${salesRep}
    END

*** Keywords ***
Collect The Results
    Capture Element Screenshot    css:div.sales-summary

*** 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 The Form Using The Data From The Excel File
    Collect The Results

We run the robot. At the end of the run, a screenshot of the sales summary appears in the Notebook:

Sales summary

Done!

What we learned

  • The Capture Element Screenshot keyword of the RPA.Browser library takes screenshots of elements.
  • Knowing how to use locators gets you a long way when automating web-based applications. Use the source, Luke!
  • There are many types of locators. Choose the simplest one for your use case!