Note: You are looking at a static snapshot of documentation related to Robot Framework automations. The most recent documentation is at https://robocorp.com/docs

Collecting the results

All the sales data has been entered. Nice! After entering all the sales data, Maria 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

We add a new keyword:

*** Keywords *** Collect the results

Taking a screenshot

The RPA.Browser.Selenium library provides the Screenshot keyword to help us with this step. We give it a locator of the element we want to take a screenshot of, and a path for the image file.

Locating the element

Let's see if the HTML markup of the page contains 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? If you want, see the How to find user interface elements using locators in web applications article to learn how to view the HTML markup of web pages using browser 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 use CSS to locate the element, our locator will start with the css: prefix. There are multiple types of locators: id, name, xpath, depending on the strategy used.

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!

Saving the file to the output directory

As the second argument, we will pass the Screenshot keyword the path to use for the screenshot image file. We want the file to be called sales_summary.png and added to the output directory.

The output folder is where Control Room will look for files generated by our robot. Check the robot.yaml specification page for more information.

Our path for the file will be this: ${OUTPUT_DIR}${/}sales_summary.png.

But what are those variables?

  • ${OUTPUT_DIR} is a special Robot Framework runtime variable that represents the output directory.

  • ${/} is a built-in variable that represents a directory path separator (/ or \). This variable makes sure the path separator will work in any operating system (macOS, Windows, Linux).

Our keyword implementation will be:

*** Keywords *** Collect the results Screenshot css:div.sales-summary ${OUTPUT_DIR}${/}sales_summary.png

Our robot will now look 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.Excel.Files 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 the form using the data from the Excel file Collect the results *** 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 for one person [Arguments] ${sales_rep} Input Text firstname ${sales_rep}[First Name] Input Text lastname ${sales_rep}[Last Name] Input Text salesresult ${sales_rep}[Sales] Select From List By Value salestarget ${sales_rep}[Sales Target] Click Button Submit Fill the form using the data from the Excel file Open Workbook SalesData.xlsx ${sales_reps}= Read Worksheet As Table header=True Close Workbook FOR ${sales_rep} IN @{sales_reps} Fill and submit the form for one person ${sales_rep} END Collect the results Screenshot css:div.sales-summary ${OUTPUT_DIR}${/}sales_summary.png

We run the robot. A screenshot of the sales summary is stored in the output folder at the end of the run.

Done!

What we learned

  • The Screenshot keyword of the Selenium library takes screenshots of elements.
  • Knowing how to use locators gets you a long way when automating web applications.
  • There are many types of locators. Choose a good one for your use case!
  • The ${OUTPUT_DIR} runtime variable represents the robot output directory.
  • The ${/} built-in variable represents the path separator for the current operating system.
  • The output folder is where we should put files that our robot generates.