UiPath

Modifying UiPath selectors, how to specify by looking for variables, anchors and elements

Understanding the selector is essential for stable operation of UiPath robots.

However, the selector is a difficult concept to understand because it is UiPath’s own way of specifying UI elements.

This article explains what a selector is, how to modify it, and how to specify it using variables, relative specification, anchors, and find elements.

 

 

 Related Articles Create a practical UiPath robot with Udemy’s online course

 

The operator of this blog, F-penIT blog

 

This site was created by translating a blog created in Japanese into English using the DeepL translation.

Please forgive me if some of the English text is a little strange

 

What is a selector?

A selector is like a textual address for UiPath to recognize UI elements such as buttons and strings in your application.

By uniquely specifying the selector and specifying the UI element to be manipulated, operations such as clicking and text input can be stabilized and made to work.

F-pen
F-pen
Selectors tend to be more stable than positional or image selectors because they are less affected by changes in UI elements.

 

How to check the selector

There are three ways to check the selector: the property selector, the selector editor, and the UI Explorer.

Check with the property selector.

You can see the selector in the properties of the activity where you need to specify the UI elements such as clicking or typing.

sea otter
sea otter
The selector is the text in the [Selector] section, circled in red in the figure above.

 

Check in the Selector Editor.

If you want to check the selector structurally, use the Selector Editor.

(1) Click […] next to the Activity Properties selector.

(2) The Selector Editor will open, and check the red box in the figure below.

 

Check with UI Explorer.

If you want to see all the selectors, use the UI Explorer.

There are two ways to open the UI Explorer: from the Selector Editor, or from the Studio ribbon.

 

■How to open from the Selector Editor
(1) Click [Open in UI Explorer] in the Selector Editor.

(2) UI Explorer will open, and check the selector in the red frame on the bottom right.

F-pen
F-pen
You can add or remove selectors by checking or unchecking the top portion of the selector editor.

 

■How to open from the Studio ribbon
(1) Click [UI Explorer] in the Studio ribbon.

(2) Click [Select Element].

(3) Click on the element for which you want to get the selector.

(4) Check the selector in the red box at the bottom right of the UI Explorer.

sea otter
sea otter
When you specify an element in “(3) Click the element you want to get the selector from”, pressing the F2 hotkey will wait for 3 seconds to select the element, so you can switch the active window.

 

Structure of the selector

Selectors are structured in a hierarchy.

The selector has the following hierarchical structure

  1. The top window of the application
  2. Parent element 1
  3. Parent element 2
  4. UI elements

 

IE’s back button is shown in the figure below

  1. IE (the top window of the application)
  2. Navigation bar (element 1 of the parent)
  3. The first one in the toolbar (parent element 2)
  4. Back button (UI element)

The back button is represented by the following selectors

 

Selectors are represented by attributes and values.

Selectors are displayed with attributes in red and values in blue.

Take the first line of the figure below as an example.

  • The attribute is [app]、[cls]、[title]
  • The value is [iexplore.exe]、[IEFrame]、[‘Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports &*’ ]
F-pen
F-pen
The first line, “app=’iexplore.exe'” indicates that the application is IE (Internet Explorer).

 

There are two ways to select: full selector and partial selector.

There are two ways to specify the selector.

  • Full selector
    This is a selector that has all the elements necessary to identify a UI element, including the top-level window (application).
  • Partial selector
    This is a selector that does not include the top level window (application), but is specified within a container such as a window attach.

 

Sample of a Full selector
・Sample Process

・Click selector

sea otter
sea otter
It’s a complete selector, so I’m including IE in the topmost window.

 

Sample partial selector
・Sample Process

・Attach Window  Selector

 

・Highlight  Selector

F-pen
F-pen
Since it is a partial selector, the first line is inherited from the “Attach window” selector and cannot be modified.

 

Fix selector.

Use the index ( idx ) attribute as little as possible.

The index ( idx ) attribute of the selector is automatically generated when the selected element has no unique information (multiple elements have the same selector).

Therefore, since idx is susceptible to changes in UI elements, it is better to avoid using it as much as possible to create a stable working robot.

Here are the steps to modify the selector of idx to another selector.

 

Sample Process
Highlight “Finance Home” in Yahoo Finance.

・Target screen

・Initial selector for highlighting

sea otter
sea otter
Since it contains idx, open the UI Explorer to see if another selector can be taken.

 

・UI Explorer before modification

F-pen
F-pen
You can use “aaname” and “Finance Home” in the upper right corner to uniquely specify the element, so check them and remove the idx.

 

・Fixed UI Explorer

 

・Modified UI Explorer2

sea otter
sea otter
I’ll click on the highlight in the modified highlight selector to see if it recognizes the element correctly.

 

・Browser when highlight-clicking

F-pen
F-pen
The “Finance Home” section was highlighted with a red frame, so we were good to go.

 

・The modified UI Explorer3

sea otter
sea otter
Next, I’ll click [Verify] to make sure there are no problems with the selector.

 

・Modified UI Explorer4

F-pen
F-pen
The [Verify] in the upper left corner is now green, so the selector is OK. Click [Save] in the lower right corner.

 

・Selector Editor

sea otter
sea otter
The selector editor will reflect your changes, so click [OK] and you’re done.

 

Use wildcards

If the value of the selector is variable, such as a file name or a date, use wildcards.

There are two types of wildcards

  • *
    Represents multiple characters.
  • ?
    Represents a single character.

 

 

Sample Process
todaysdateサイトの現在日付をハイライトする。

・Target UI element

 

・Selector before highlight modification

F-pen
F-pen
Since aaname contains a concrete date, it may not be possible to specify an element after tomorrow.

 

・Selector with modified highlighting  1

sea otter
sea otter
The day of the week, month, and day are n-digit, so *, and the year is fixed at 4 digits, so ???? I’ll fix it to

 

・Selector with modified highlighting  2

F-pen
F-pen
Click on Highlight and Validate to check that the modified selector has successfully specified the element.

 

・Selector with modified highlighting  3

sea otter
sea otter
The validation in the upper left corner is now green and the selector is OK, so I click OK in the lower right corner and I’m done fixing the selector.

 

Use variables

If the value in the selector changes regularly, replace the fixed value in the selector with a variable.

The fix is to edit the selector item of the target activity’s properties as text.

 

F-pen
F-pen
Note that the selector editor is not used.

 

Sample Process
Highlight the location of the specified calendar in todaysdate.

 

・Screenshot of the target site

 

・Highight fixed  Properties

 

・Highight Variable  Properties

・Execution result

 

How to modify the selector
(1) Click on the text field of the selector for the activity to be modified.

 

(2) Edit the selector.
・Before correction

・After correction

sea otter
sea otter
tableCol=’4′ tableRow=’6′  を tableCol='”+strTableCol+”‘ tableRow='”+strTableRow+” へ修正しているよ

 

・Selector text

・Before correction
"<html title='TODAY*' /><webctrl isleaf='1' tableCol='4' tableRow='6' tag='CENTER' />"

・After correction
"<html title='TODAY*' /><webctrl isleaf='1' tableCol='"+strTableCol+"' tableRow='"+strTableRow+"' tag='CENTER' />"

 

 

Relative specification of selectors

Using the Anchor Base

Use “Anchor Base” when the content cannot be specified in the stable selector.

Specify the content indirectly by using “Find Element” within the “Anchor Base” to specify the stable content near the content.

The “Anchor Base” is located in UIAutomation > Element > Find.

“Find Element” is located in UIAutomation > Element > Find.

 

Sample Process
Highlight the man-hour probability for Tokyo in the weather forecast on the japan.travel website.

・Target Sites

・Anchor Base  Properties

 

・Find Element  Properties

sea otter
sea otter
I’m setting the selector to “Tokyo”

 

・Highlight  Properties

F-pen
F-pen
Since “Find Element” specifies Tokyo, it becomes a selector that specifies the relative man-hour probability.

 

・Execution result

 

Use the relative selector

If the content cannot be specified with a stable selector, there are other ways to use relative selectors besides anchor-based.

Specify a stable selector near the content to indirectly specify the content.

Relative selectors are created using the UI Explorer.

 

Sample Process
Highlight the maximum temperature for Los Angels in the weather.us weather forecast.

・Target Sites

・Highlight Directly specified selector  Properties

F-pen
F-pen
It is an unstable selector because there is no information to specify Los Angeles and it contains an idx that is automatically generated by UiPath.

 

・Highlight Selector for relative specification  Properties

sea otter
sea otter
After finding Los Angeles, it is a stable selector because it specifies the relative maximum temperature.

 

・Execution result

 

How to modify the selector
(1) Click […] on the selector.

(2) Click [UI Explorer]

(3) Click [Select Anchor].

F-pen
F-pen
Since there is no stable selector, we will use anchors to specify the selector.

 

(5) Specify [Los Angeles].

(5) Make sure that the selector with the anchor designation has been created.

(6) Modify the temperature of aaname to a wildcard *.

sea otter
sea otter
Since the temperature changes from day to day, use the multi-character wildcard *.

 

(7) Click on “Highlight” and “Verify.

F-pen
F-pen
Checking the modified selector for problems with highlighting and verification

 

(8) Click “Save”.

(9) Click OK

This completes the modification of the selector.

 

Using Find Children

Use “Find Children” to specify the content in the specified selector to the selector of the child elements.

Find Children to get the child elements, and For Each to perform the activity on the selector of the child elements.

“Find Children” is located in UI Automation > Element > Find

 

Sample Process
Prepare and highlight the 4-day weather forecast on weather.com.

・Target Sites

・Find Children  Properties

sea otter
sea otter
I’m using the selector to specify the date frame in the upper left corner.
F-pen
F-pen
The output Child is set to the “Uipath.Core.UIElement” type.

 

・For Each  Properties

sea otter
sea otter
Core.UIElement” output from “Find Child Elements” is specified for TypeArgument in Misc.

 

・Variables

・Execution result

F-pen
F-pen
The weather forecast for the next four days is highlighted in order.

 

Summary

  • A selector is like a textual address for UiPath to recognize UI elements such as buttons and strings in your application.
  • You can modify the selector from the property selector, selector editor, or UI Explorer.
  • Selectors can also be specified by wildcards or variables.
  • There are three ways to specify a relative selector: Anchor Base, Relative Selector, and Find Children.

 

Back to Table of Contents

 

 Related Articles Create a practical UiPath robot with Udemy’s online course

 同カテゴリ UiPath