Book demo Start trial

WEB AUTOMATION - Lesson 5: Reading text and numbers

  • How to read and retrieve text, selections, numbers etc. from a web page, including text fields, drop-downs, and radio buttons.
Go to next video.

You will learn:

  • How to read and retrieve text, selections, numbers etc. from a web page, including text fields, drop-downs, and radio buttons.
Go to next video.
Download sample file:
Radio button sub-flow.

TRANSCRIPT

Welcome to the fifth lesson in web automation with LEAPWORK

In the previous lessen we looked at different ways of filling data into a web form,
both hard coded data and also by reading the data from a database.

In this lesson we will do - almost - the opposite and focus on reading values from a web page.
We will look at the most common controls on a web form
and also look at how we can simply read static text from a web page.

I have a simple flow with a Start Web Browser block,
with the URL set to facebook.com, and an open browser for the design of the flow.

I have added values to the registration form in advance.

We will start simple,
and read the value in the first name field
using a Get Web Text building block.
This block will return the textual part of the captured element,
so we start by capturing the First Name field.

To check the result of the read operation, I'll add a Log message after
the Get Web Text block,
and input the "Text found" into the Log Message block.

When we run the flow from the Get Web Text
we see that the text found matches the value in the Firstname field.

Another way of using the get Web Text is to read static text on the web page.
For instance reading some of the marketing text on the registration form.

We change the captured element to the "See photos and updates" section,
and select an element that includes both the bold and the normal text.
Running this block would simply return the text as we saw with the Firstname field,
so let's try to use another feature on the Get Web Text block: the Format.

This feature allows us to specify exactly which part of a larger text we want returned,
by specifying a pattern - or a format - that the return text should match.
In this example we could specify that the text we want - shown as the TEXT token -
is the text following the word "updates".

Let's run the block.

It returned "from friends in News feed", which is exactly the text we wanted.

Another similar feature is the Filter,
that can be used to check if a text contains, starts with or ends with a specific word or phrase.
To exemplify this I select the "contains" option and insert "photos" as the word to look for.
If this word is not found, the building block will fail and trigger the "Not found" connector.
if the word "photos" is found everything is good, and the top connector will trigger.

If we run the block, we see that the text was not found.
Because of the Format clause specified, the text didn't contain "photos".

Let's try to run it without the Format.

Success - now the text contain "photos".

The next control to look at is the Birthday fields. 3 dropdowns for the month, day and year.
To read the values from the dropdown we use a Get Web Dropdown building block,
and capture the dropdown to get the selected value from.

When we expand the Get Web Dropdown block,
we have several options.

We can select to get the "Index" of the selected element in dropdown.
This is simply the number in the list, so if the user selected element number 4, this would return 4.

The "Selected text" returns the text the is visible in the list.
In this case "Sep".

The last option is to get the value behind the selected element.
Remember the way a dropdown is defined:

$$$ Powerpoint

Every entry has the visible text,
which is the "Selected Text" option,
and a value, which is the "Selected value".

Let's try to output all of them into one log message.
When we pull the "Selected index" onto the Log Message block it expands
and allow us to add the value to a FIELD.

Fields are like tokens, that can be used in composing a message.
We add the other properties as values as well,
and create the message.

Writing "Selected index:" and then insert FIELD1,
and add the 2 other fields as well.

Let's run the blocks.

It outputted: 9, Sep and 9 again.

Let's try to change the month and run the block again.

4, Apr and a 4.
So this is how to read data from a dropdown field in a web form.

Radio buttons are a bit more complicated that the other control types.
They look simple, but it is actually a number of controls,
which have an ID in common,
that prevents more than one of them to be selected at the same time.

Unfortunately the best - and in most cases only - way to read the value is to use Javascript
I have an example here using Javascript,
where the complicated bit is encapsulated in a sub flow.

The first thing to do is capture one of the radio buttons.
It doesn't matter which one is captured -
it's basically just the name that ties the individual options together that is interesting.

We capture the Female radio button and connect the "Found element" -
which is the radio button -
to the "Radio button element" input connector on the sub flow.

Then we connect the output value to a log message,
to be able to see changes in the selection in a simple way

If we just run the flow from when we capture the radio button,
we can see that the returned value is empty.
This is because no selection has been made.

If I manually select "Male" and run it again,
we get the value "2" back.
And selecting "Female" returns a "1".

An example flow including the radio button sub flow,
can be downloaded from this page and imported into your local solution.

Enough about radio buttons - what about numbers?
It's basically the same, but we would use the Get Web Number instead.
This block will extract the number part of the captured element instead of the entire text.

Let's try to capture the current year,
from the facebook copyright statement at the bottom of the registration form.

We again use a Log message to output the number found
and run the block.

"2018" is the current year.
Just as with the Get Web Text we can specify both formats and filters,
now with filters suited for handling number operations.

In this lesson we looked at various ways to
read and retrieve text, selections, numbers etc. from a web page
We looked at text fields, dropdowns, radio buttons