Dynamic or Variable Selectors in UiPath

. 2 mins read

Dynamic or Variable Selectors in UiPath

In this post, we would discuss how to use dynamic or parameterized selectors in UiPath.

To explain parameterized selectors, we use Automation Challenge Round 1 from the website RPA Challenge by UiPath.

The challenge is to create a workflow that can enter data to the form and submit. We have around seven fields on the web page and they all change their properties on each refresh. As you might already know, we can achieve this by indicating an anchor for each of these fields.

So, I need to capture all the fields and its anchor and then design the workflow to enter details in all those fields.

Let us capture the field First Name. The selector would look something like below.

<html app='chrome.exe' title='Automation Challenge' />
<webctrl aaname='First Name' tag='LABEL' />
<nav up='1' />
<webctrl tag='INPUT' />

To identify the First Name text box, I used the anchor with aaname First Name.

Now let us capture another element, say Email. The selector for email would look like below.

<html app='chrome.exe' title='Automation Challenge' />
<webctrl aaname='Email' tag='LABEL' />
<nav up='1' />
<webctrl tag='INPUT' />

If we compare the selectors, the only change is the aaname. So if we parametrize, we can identify any element.

To do this let us declare a variable fieldLabel.

Now we have to use the variable fieldLabel inside the selector. We can do it like below.

"<html app="" chrome.exe"" title="" Automation Challenge"" /><webctrl aaname=""" + fieldLabel + """ tag="" LABEL"" /><nav up="" 1"" /><webctrl tag="" INPUT"" />"

See how we have introduced the variable fieldLabel in the selector. The entire string is in a single line and double quotes are escaped. The correct way to escape double-quotes in VB is by doubling the double-quotes.

To use this parameterized selector, we need to enter the string into the Selector field under Target (Input » Target » Selector). Entering a value in the selector pop up window does not work.

You can also save the string to a variable and use that variable as the selector.

Now that we have a variable selector, you can enter the value in any field by changing the variable fieldLabel.

A sample workflow is attached below. Follow the steps below to make the workflow work or you can modify it.

  • Open RPA Challenge Website on the Chrome browser.
  • Navigate to the first challenge by clicking start.
  • Make the window active.
  • Run the workflow from UiPath.

Download Sample Project

RPA
Using Inject JS Script Activity in UiPath
02 Feb 2021

A comprehensive guide on how to use Inject JS Script Activity in UiPath.

RPA
Set the version of Google Chrome browser opened by UiPath
02 Feb 2021

This post explains how to set the version of Google Chrome or any other browser opened by UiPath, when you have multiple versions installed.

RPA
How to deserialize JSON in UiPath?
27 Feb 2020

Tutorial on how to properly deserialize JSON with UiPath Web Activities. Explains the concept of JSON Array and JSON Object.