

- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
1. Two objects on the page
For this example let's use the webpage X-Rates; https://www.x-rates.com/table/
This page has two tables on it with overlapping information. There is the TOP10 - well, on top - and the full alphabetical list below. Let's try to capture the Top10 table using the chromium connector, Capture any element in the table and use the up-arrorw till you get to the table element. Give it a name like 'Top10Table' and capture it with the '+' sign.
Back in the connector do a 'Refresh' in the context menu of the newly captured entity. You will see it returns with an ambiguous match shown by the red 2 at the end.
Notice the generated Locator, it should be set to CssSelector with a series of HTML Tags like this:
div#content > div > div > div > div > table
So essentially our connector is trying to find a table tag which is nested in 4 DIV containers within a DIV container with an ID as content. If you look at the source code of the webpage, this definition matches both the tables within it. We call this an ambiguous hit where the computer vision isn't sure which one is actually needed. Ideally the locator can be enriched with more information to become less ambiguous - and yes, we will do that in a next step, but for now let's keep it that way and see how our robot can still process the information. Accept the setup and close the Connector dialog.
In the design studio double click on the newly created connector element within the Project Explorer to see the object's methods being listed in the Object Explorer. It will look like this:
The methods needed to work with ambiguous hits are GetInstanceCount and SetElementIndex. Drop GetInstanceCount onto the canvas and Run it to see what happens. Once complete check the Return-Value, it should be 2.
So this is how the robot can find out how many hits there are. Using SetElementIndex we can define which of the hits we actually want to process. Combining it with a for-loop we can easily navigate all the hits and do whatever we need with the elements. To conclude the table example, let build the robot like this:
Executing this robot should report a count per table. You can imagine to do any kind of work in the loop part.
Some best practice using this approach (not shown in above screenshot):
- Use a SetElementIndex outside the loop to make sure you start at index 0.
- The elements count from 0 to count-1, in order for your loop to not fail it is recommended to transform the for loop 'To' data input port to stop at Count-1. This can be achieved with a simple transformation like
Return Value-1
on the data input port.
2. Improving the locator
Now let's shift gears and see how we can improve the locator to get less ambiguity. Inspect the web page to check on the two tables in source code. The tags in question are these two:
<table class="ratesTable" cellpadding="0" cellspacing="0">
<table class="tablesorter ratesTable" cellpadding="0" cellspacing="0">
The only difference we can use to our advantage is the class attribute in this case.
Go back to RPA Design Studio and open the connector configuration to see how we can use that. Select the captured element again and look in the bottom half where it says MATCH ATTRIBUTES, the connector already extracted the available attributes as potential criteria, just nothing selected as of yet. Select the entry for Attribute class Equals ratesTable.
With the entry selected inspect the PROPERTIES section of the screen. It lists how this Matching Rule is evaluated. The default is comparing using Equals, but other options exists as well like StartsWith, EndsWith, Regex or more. This allows to configure powerful rules to find the correct elements.
For this case a simple equals ratesTable as automatically provided is enough. Refresh the element to see the ambiguity disappear.
Executing your robot once more will only return one count - the one of the first table on the page.
3. Adding a dynamic aspect
Using Matching Rules is already a powerful concept when working with web pages. What about changing these Matching Rules dynamically based on some input?
Using the example above again... lets assume we have processed the Top 10 table but didn't find what we where looking for and now want to scan the other table as well - I know, pretty artificial as an example, but hey, it serves the purpose.
We could now either fall back to the ambiguous hit and process all tables, or we could capture the second table as new element using the different class-tag.... there is yet another option.
Every active match rule in an element can be changed directly from our robot. Inspect the methods once more which are available for our Top10Table element. There is one named SetMatchRuleValue.
Drop it to the canvas, it will render as a simple box with not a lot of options. Highlight it and click the gear icon above to open its configuration.
All active matching rules will be listed allowing to select which ones we want to influence as part of the robot flow. Select class to make this an input value to the component.
This allows to override the MatchRule value defined in the connector configuration. We configured it to look for a table where class=ratesTable. For testing, set the input data port to tabelsorter ratesTable. Connect it with a GetTable component
When executing this part the component will return the second table on the page, even though the element configuration was actually pointing on the first one. We can use this method to do all kinds of interesting lookups. Assume we need to find a bespoke currency row, we can define an element to a cell in the first column and use the override to define which one we actually one we want dynamically. How? Here we go....
Open the Chromium connector configuration again and capture a table cell where any currency name is listed. I picked the first column of the fifth row in the first table... my locator looks now like this:
div#content > div > div > div > div > table > tbody > tr:nth-of-type(5) > td
If you refresh this element now there should be an ambiguity of 6 as the table we selected does have 3 cells in that row, and the second table also has a 5th row with 3 cells - not that helpful just yet.
Challenge: Build a for loop on all 6 elements and check the returned data.
As we cannot be sure our currency will always be in the 5th-row, remove that part of our locator.
div#content > div > div > div > div > table > tbody > tr > td
Refreshing this one should give you 189 hits. Good. Now we need to add a match rule to find the currency we want. On MATCH ATTRIBUTES click to get a new empty match rule. Highlight it.
This will load the PROPERTIES window. The X-Rates web page unfortunately does not have any nice attribute which we can use, so we need to check for the text in the cell itself. For this we need to setup the properties to match on Name InnerHTML, Type to Property and Value to whichever currency you want to search for, e.g. Euro. Refresh the element... you probably get 2 hits as Euro is listed in both tables - right?
Go back to the design Studio and build a sample process with SetMatchRuleValue and GetInnerHTML like this:
Obviously the GetInnerHTML will return just the value we where searching for, not much useful. I guess you can imagine though that we could do anything with the found object like Click, Focus, Send Keys,... And this all without looping through a list of elements. Pretty powerful options....
Note: the same technique works with other connectors like the Windows one as well. Go end check it out...
Now let me know in the comments how you use these features in your robots....
- 1,404 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.