Filling in the sales form
The eagle has landed! 🦅
Our robot logged in to the intranet!
The page now shows a form on the left where Maria can fill the sales data for one sales representative, and it looks like this:
The next logical step in our task then, using plain English, will be
Fill And Submit The Form.
*** Tasks *** cell like this:
*** Tasks *** Insert the sales data for the week and export it as a PDF Open The Intranet Website Log In Fill And Submit The Form
As we have learned, we need to implement the keyword so that our robot knows what to do. Let's add a new keyword cell before the task cell:
*** Keywords *** Fill And Submit The Form
Eating an elephant 🐘
Looking at the form, it seems that it is composed of three text input fields and one field where one can not type in. Looks complicated! 🤯
Breathing intensifies, beads of sweat appear on the software robot developer's forehead.
Out of nowhere, a deep voice rumbles:
There is only one way to eat an elephant: a bite at a time.
Right. We can tackle any challenge by taking small steps. Try the simplest thing you can think of first. We do not have to get everything done properly on the first try. Iterating is the key to success!
Let's start our "simplest possible solution" experiment by just trying to submit the form, without worrying about inputting anything to it. That's right! We just want to see what happens. To broaden our automation skills, instead of the
Submit Form keyword, we decide to experiment with an alternative way. The
RPA.Browser library provides a
Click Button keyword. Let's use that one here! The keyword can find the submit button by label:
*** Keywords *** Fill And Submit The Form Click Button Submit
Ok, that should do the trick. Clicking on the
>> icon in the toolbar, we run the robot and celebrate our success!
Oh no! It did not work!
Hold your horses! 🐎🐎🐎
Looking at the error log, we can see:
Button with locator 'Submit' not found.
Wait. What? The button is there. You have seen it with your own eyes. What is going on here?
Scrolling to the bottom of the Notebook, you see an error message. Right after the error message, a screenshot of the browser displays the last thing your robot saw on the moment of failure. It is a screenshot of the login page:
It looks like the robot could not find the form, because the form was not there yet. Your robot is really fast. It does a thing and continues with the next as soon as it can. Faster than Maria ever would. That is a good thing of course, but it also means that we need to teach the robot some patience.
Luckily for us, there is an
RPA.Browser keyword we can take advantage of:
Wait Until Page Contains Element. Provided with a locator, it will, well, wait until the page contains the said element (talk about good naming, eh?).
Where should we do this waiting? We could add the keyword in our
Fill And Submit The Form keyword. Calling it in the
Log In keyword might work, too. In the end, we decide that the login operation can be considered successful if the page contains the sales form.
Armed with the
id attribute of the sales form (we found it by inspecting the HTML markup), we edit our login keyword like this:
*** Keywords *** Log In Input Text id:username maria Input Password id:password thoushallnotpass Submit Form Wait Until Page Contains Element id:sales-form
We run the robot again:
After submitting the login form, it waits patiently for the sales form to appear and proceeds to submit the form. The browser stays open, and we see the form complaining about missing information. Progress! We managed to eat a small piece of the giant elephant and can continue devouring the beast, a bite at a time.
The evolution of a solution, Part I 🥚
In the spirit of taking small steps towards our ultimate goal, we are going to cut some corners. We'll be hard coding our sales data for now. That is, we are not concerned about using real data just yet. That is perfectly acceptable at this point. We want to see that our general flow works. This way, we can find possible technical blockers as soon as possible. We will create a crude solution first and polish to production quality later.
Using our previous knowledge of the
Input Text keyword, we can easily fill the
Last Name and
Sales Results fields of this new form. We just need to use the
name of each field as the locator:
*** Keywords *** Fill And Submit The Form Input Text firstname John Input Text lastname Smith Input Text salesresult 123 Click Button Submit
The sales target, however, is not a simple text field, but a
select HTML element. We need to use a different keyword to select a value from the ones that the field allows.
Select From List By Value to the rescue! The keyword takes a locator and a value as arguments:
*** Keywords *** 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
Here's how our complete robot looks like now:
*** Settings *** Documentation Robot to enter weekly sales data into the RobotSpareBin Industries Intranet. Library RPA.Browser *** 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 Input Text firstname John Input Text lastname Smith Input Text salesresult 123 Select From List By Value salestarget 10000 Click Button Submit *** Tasks *** Insert the sales data for the week and export it as a PDF Open The Intranet Website Log In Fill And Submit The Form
We try running our robot again:
Success! Poor "John Smith" has his horrible performance entered in the intranet.
We now have the basic outline of our form filling keyword done!
Next, we need to figure out how to read real data and how to enter the data for multiple people in sequence (looping).
What we learned
- There is only one way to eat an elephant: a bite at a time.
Click Buttonkeyword can click on buttons using the label as the locator (other locators work, too).
- Use the
Wait Until Page Contains Elementto wait before proceeding to avoid failures due to the robot advancing too fast.
- Hard coding data is an acceptable practice to progress and to find potential technical blockers more quickly.
- Take small steps. Iterate often.