Tutorial

RPA form challenge robot

Creating a software robot to solve the form challenge at rpachallenge.com

Robocorp

This robot will solve the form challenge posted at http://rpachallenge.com.

The challenge consists of downloading an Excel spreadsheet, extracting its data and filling a form on the website with the extracted data ten times.

It sounds pretty simple! However, the catch is that each time the form gets submitted, the fields' position and order is shuffled around, so you need to find a good way to identify the right fields each time the form is displayed.

RPA form challenge

When run, our robot will:

  • download the test Excel file from rpachallenge.com
  • collect data from the downloaded Excel file
  • start the challenge by clicking on the Start button
  • loop through the data and fill the form ten times
  • take a screenshot of the results page
  • write log files
  • close the browser

Robot script

Robot script explained

Now let's look at what we are telling our robot to do in detail.

Settings section

In this section of the tasks.robot file, we add a description of our robot and reference the libraries that we want to use:

Our robot uses these three libraries:

  • RRPA.Browser.Playwright: to interact with the browser
  • RPA.Excel.Files: to read the contents of our Excel file
  • RPA.HTTP: to download the Excel file from the challenge website.

These libraries are provided by the rpaframework package, a set of well-documented and actively maintained core libraries for Software Robot Developers.

Tasks and Keywords

We are defining the challenge as a task that calls keywords coming from the libraries we are importing, and also some that we define ourselves.

Task: Complete the challenge

Keyword: Start the challenge

The default run mode with the RPA.Browser.Playwright library is headless (no browser GUI). The New Page keyword opens a browser to the given URL. If a browser is not already open, it will be opened first. To see the browser GUI when using the RPA.Browser.Playwright library, use the Open Browser keyword.

Then, using the Download keyword from RPA.HTTP, it will download the Excel file locally, overwriting the file if it happens to exist already. Once the file is downloaded, it will start the challenge using the Click keyword, provided by the RPA.Browser.Playwright library.

Because there are no other buttons of type button, we can just pass the type to the Click keyword, and it will just work!

Keyword: Fill the forms

This keyword is where most of the work is done. Let's have a look at it in detail:

  1. ${people}= Get the list of people from the Excel file:

    Here we are creating a variable, and we are assigning to it the Excel data by using a new keyword that we called Get the list of people from the Excel file:

    We are using the RPA.Excel.Files library to manipulate the Excel file (Keywords: Open Workbook, Read Worksheet As Table, Close Workbook), returning the data as a Table, so that we can iterate over it in the next step.

  2. Looping over the people data:

    Here we get the table rows data @{people}, and we call the Fill and submit the form keyword for each row @{person}, using a FOR loop.

  3. Fill and submit the form ${person}

    Now that we have the data from one individual row, with this keyword we can fill the form on the page.

    The RPA.Browser.Playwright library provides a keyword to set an input field (Fill Text), but how can we identify each form item? We cannot rely on the order of the fields or their position on the page because, as part of the challenge, they will move around each time we submit the form.

    We have to dig deeper to find a reliable way to identify each field. Let's have a look at the source code of the form inputs, for example the "First Name" field:

    Typically, we would use the id, or name HTML attributes to identify a form field, but the creators of the challenge did not make it easy for us because these attributes change each time the form is submitted. However, we can see that there is another attribute that does not change: ng-reflect-name. Let's use that one!

    So, using XPATH, our locator for the "First Name" field will become:

    Learn more about how to find interface elements in web applications and the concept of locators.

    Now with our locators and the Fill Text keyword we can fill each field in the form with the corresponding data, and then click the submit type button:

    Note: the keys in our ${person} dictionary are the column headers from the first row of the Excel file: RPA Form challenge Excel file

Keyword: Collect the results

After all the forms have been filled, the site will display a congratulations message with statistics about the accuracy and how long it took to complete the challenge. Looking at HTML source of the page, we can see that the congratulations message has a CSS class of congratulations: the robot will take a screenshot of it (Take Screenshot ) and save it to a file.

RPA challenge congratulation screen

At the end, we tell the robot to Close Browser.

Python script

As you can see, the problem to solve is the same, the code just looks a bit different. The same libraries are used for Excel and HTTP, just that instead of using keywords we use functions.

The browser library uses implictly Playwright so we directly import that.

Portal examples

You can find both these examples as a template on our portal:

Summary

Using this example robot, you learned some concepts and features of both Robot Framework and RPA Framework:

  • Downloading a remote file via the RPA.HTTP library (Download)
  • Reading Excel files and working with the data (RPA.Excel.Files)
  • Locating specific elements in a webpage using their label or a custom attribute with XPath
  • Filling web forms and clicking buttons (Fill Text, Click)
  • Taking screenshots of elements of a webpage (Take Screenshot)