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:
Our robot can handle this case too!
Let's add a new step to our task. We'll call it Collect the results
:
We add a new keyword:
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:
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 thesales-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 therobot.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:
Our robot will now look like this:
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 theSelenium
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.