RPA Selectors and UI Elements
A selector is a piece of code that uniquely identifies a UI element on the screen — a button, a text field, a label, a dropdown, or a window. The RPA bot uses the selector to find and interact with the exact element it needs. If the selector cannot locate the element, the bot throws an error and stops at that step.
Think of a selector like a postal address for a screen element. Just as a parcel needs a specific address to reach the right door, a bot needs a precise selector to reach the right button on the right screen.
Selector Structure
Selectors in UiPath are written in XML format. Each tag in the XML represents one level of the UI hierarchy — from the outermost window down to the specific element.
Example: A Selector for the SAP Login Button
<wnd app='saplogon.exe' cls='SapClass' title='SAP Logon 750' /> <wnd ctrlid='2' /> <wnd ctrlid='109' title='Log On' /> Breaking it down: ───────────────────────────────────────────────────── Level 1: Application window (SAP Logon 750) Level 2: Sub-window within SAP (control ID 2) Level 3: The specific "Log On" button (title='Log On')
Example: A Selector for a Web Form Field
<html app='chrome.exe' title='Login – Company Portal' /> <webctrl tag='INPUT' type='text' id='username' /> Breaking it down: ───────────────────────────────────────────────────── Level 1: Chrome browser with specific page title Level 2: An INPUT element of type text with ID "username"
Good vs Bad Selectors
Not all selectors are equally reliable. A good selector is stable across different screen states and machines. A bad selector breaks when the application changes even slightly.
Bad Selector (Too Specific)
<html title='Login – Company Portal – Chrome – Tab 1 of 3' />
<webctrl aaname='Username' idx='4' parentid='form-row-2' />
Problems:
- Title changes when tab count changes ("Tab 1 of 4")
- idx='4' changes if elements are added above it
- parentid may change in a UI update
Good Selector (Stable)
<html title='Login*' /> <webctrl id='username' tag='INPUT' /> Why it's stable: - Wildcard (*) in title handles tab count changes - id='username' is a permanent developer-assigned ID - Not dependent on position or surrounding elements
Selector Properties to Use and Avoid
| Property | Stability | Notes |
|---|---|---|
| id | High | Developer-assigned, rarely changes |
| name | High | Usually stable in forms |
| automationid | High | Set by developer for accessibility |
| type / tag | High | Element type (INPUT, BUTTON, etc.) |
| title | Medium | Use with wildcards (*) where possible |
| aaname | Medium | Accessible name — can change with locale |
| idx | Low | Position-based — breaks when elements shift |
| class | Low | CSS class names change with updates |
| parentid | Low | Parent container ID changes with redesigns |
The UiPath Selector Editor
UiPath Studio provides a Selector Editor — a visual tool for inspecting and modifying selectors. You open it by clicking "Edit Selector" on any UI activity. The editor shows the full selector XML and highlights which properties are included.
Using Wildcards in Selectors
Wildcards make selectors flexible. The asterisk (*) matches any text. The question mark (?) matches exactly one character.
Exact (fragile): title='Invoice 1045 – SAP – ECC 6.0' With wildcard: title='Invoice * – SAP*' The wildcard version works for invoice 1045, 1046, 2000, or any invoice number — without changing the selector.
Dynamic Selectors
Sometimes the selector contains a value that changes with each bot run — such as a document number, a row number, or a customer ID. You handle this by making the selector dynamic — injecting a variable value into the selector at runtime.
STATIC (breaks for different customers):
<webctrl id='customer_12345_profile' />
DYNAMIC (uses a variable):
<webctrl id='customer_' + customerID + '_profile' />
In UiPath, dynamic selectors use curly braces:
<webctrl id='customer_{{customerID}}_profile' />
When the bot runs with customerID = "98765", the selector becomes:
<webctrl id='customer_98765_profile' />
The UI Explorer Tool
UiPath includes a UI Explorer tool that lets you inspect any element on screen and see all of its properties. You hover over an element and the tool displays every attribute — its ID, name, class, position, and parent hierarchy. Use UI Explorer to build better selectors when the auto-generated one is fragile.
Anchor-Based Selectors
When an element has no unique properties, use an anchor — a nearby element that IS uniquely identifiable. The bot locates the anchor first, then finds the target element relative to it.
Example: A table row where the "Edit" button has no unique ID Anchor: The text label "Invoice INV-2024-0451" in the same row Target: The "Edit" button to the right of that label Strategy: 1. Find the row containing "INV-2024-0451" (the anchor) 2. Find the Edit button within the same row (relative position) UiPath Anchor Base activity handles this pattern automatically.
Image-Based Automation (When Selectors Fail)
In some environments — particularly Citrix virtual desktops — the RPA tool cannot read the underlying UI properties. Selectors do not work because the entire screen is delivered as a flat image. In this case, the bot uses image recognition to locate elements by their visual appearance.
- The bot takes a screenshot of the screen
- It searches for a saved template image (like a button icon) within the screenshot
- It clicks at the location where the template image was found
Image-based automation is less reliable than selector-based automation. It breaks when screen resolution changes, themes change, or elements move position. Use it only when no selector-based alternative exists.
Selector Troubleshooting Guide
| Problem | Likely Cause | Solution |
|---|---|---|
| Selector not found | Element not loaded yet | Add Element Exists wait before the activity |
| Wrong element clicked | Selector too generic, matches multiple elements | Add more specific properties to the selector |
| Works in dev, fails in prod | Selector includes machine-specific property | Remove machine-specific attributes; use wildcards |
| Fails after app update | Developer changed element ID or class | Re-indicate the element to generate a fresh selector |
| Fails on different language OS | Selector uses display text that changes with locale | Use ID or AutomationID instead of text-based properties |
Summary
Selectors are XML addresses that identify UI elements on screen. Good selectors use stable properties like ID, name, and AutomationID. Bad selectors use position-based properties like idx or dynamic text that changes. Use wildcards to make selectors flexible. Use dynamic selectors when a value in the selector changes with each run. Use Anchor Base when an element has no unique properties. When all else fails in virtual environments, fall back to image-based automation. Mastering selectors is one of the most practical skills in RPA development — fragile selectors are the number one cause of bot failures in production.
