UI selector

On this page 8

A UI selector is a structured description of a user interface element, written as a set of attributes and hierarchy levels, that a software robot uses to locate the exact window, button, text field or table cell it must read or operate. In RPA, the selector is the link between a recorded action, such as “click Submit”, and the concrete on-screen object that receives that action at run time.

Selectors decide whether an automation survives everyday change. A well-built selector keeps working when a window title gains a date or a web page reorders its menu, while a fragile one fails silently or, worse, clicks the wrong element. For that reason, selector design is one of the core skills in robotic process automation and UI automation in general.

How a UI selector identifies an element

A UI selector identifies an element by matching a chain of attribute filters against the live object tree that the operating system or browser exposes. The robot starts at a top-level window or browser tab, then descends level by level until a single node satisfies every condition. Most RPA platforms store this chain as an XML-like string, a JSON object or a visual tree, but the logic underneath is the same.

The attributes come from the accessibility and automation frameworks of the target technology. On Windows desktop applications, these are typically Microsoft UI Automation (UIA) or the older MSAA interface; in browsers, they are the Document Object Model (DOM) properties of HTML elements; in Java and SAP clients, dedicated bridges such as the Java Access Bridge or SAP GUI Scripting supply them. The selector cannot use any property the framework does not expose.

A typical selector has two parts. The top-level (window) part names the application process, window title or browser URL, and the element part narrows down to the control by role, name, automation ID, class or position. Separating them allows a robot to attach to an already open window once and then run many element-level searches inside it, which is faster and more stable.

The following table lists the attributes most often used in selectors and how reliable each one tends to be.

AttributeTypical sourceStabilityMain risk
Automation IDUIA, developer-assignedHighMissing in older or custom controls
HTML idDOMHigh if staticGenerated ids change per session
Name or labelUIA, DOM textMediumChanges with language or wording
Role or control typeUIA, ARIA roleMediumToo generic on its own
Class nameWin32, CSS classLow to mediumShared by many elements, styling changes
Index or positionTree orderLowBreaks when siblings are added
Common selector attributes and their reliability

Types of selectors in RPA tools

RPA tools offer several selector types because no single approach works for every interface. The choice of selector type depends on what the target application exposes and how often its layout changes. Leading platforms such as UiPath, Automation Anywhere, Blue Prism and Power Automate for desktop all support most of the variants below under different product names.

Selector typeHow it worksBest suited for
Full selectorIncludes the window and element parts in one stringActions that open or switch windows
Partial selectorElement part only, inside an attached windowMany steps in the same screen
Dynamic selectorAttribute values filled from variables at run timeRows, invoice numbers, user names
Fuzzy selectorAccepts values above a similarity thresholdLabels with minor text variations
Anchor-based selectorFinds a target relative to a stable nearby labelForms with unlabeled input fields
Image or OCR selectorMatches pixels or recognized text on screenVirtual desktops and remote sessions
Selector types and when each applies

Modern tools increasingly combine several of these methods into multi-anchor or unified targeting. The robot first tries the structured selector, then falls back to an anchor or an image match if the first method fails. This layered approach improves resilience against interface changes, but it also makes it harder to know which method actually matched, so logging the winning strategy is good practice.

Wildcards, variables and dynamic attributes

Dynamic attributes are the most common cause of selector failure, and wildcards and variables are the standard remedy. A window title such as “Invoice 48213 – Editor” changes for every document, so the selector replaces the variable part with a wildcard, typically * for any sequence of characters and ? for a single character.

Wildcards should be used as narrowly as possible. Replacing the whole title with * makes the selector match any window of that process, including an error dialog that happens to be in front. A better pattern keeps the stable fragment, for example Invoice * - Editor, so the match remains specific.

Variables go one step further by injecting run-time data into the selector. When a robot loops through a table of customer records, it can insert the current customer number into the selector of a grid row and click exactly that row. Some tools also accept regular expressions for attributes, which allow precise patterns such as a fixed prefix followed by exactly six digits.

UI selectors belong to a family of techniques for interacting with software through its interface, and each technique has a different balance of precision and robustness. Selectors are generally preferred whenever the target application exposes a usable object tree.

TechniqueWhat it relies onStrengthWeakness
UI selectorObject tree attributesPrecise, independent of screen resolutionNeeds an accessible object model
Screen scrapingText or pixels captured from the screenWorks on almost any displaySensitive to fonts, scaling and themes
Record and playbackRecorded actions with auto-generated selectorsFast to createGenerated selectors are often brittle
Coordinate clickingFixed x and y positionsSimpleFails when windows move or resize
API integrationDocumented service interfacesFast and stableRequires an available API
Selectors versus other interface techniques

In practice, record and playback is often the starting point, and an experienced developer then reviews and hardens each generated selector. When a stable API exists, it is usually the better choice than any UI-level technique, because interface automation always inherits the fragility of the presentation layer.

Building robust selectors

A robust selector uses the fewest attributes that still identify exactly one element, and it prefers attributes that developers assign deliberately over those generated by frameworks. The following practices are widely followed by RPA teams.

  • Prefer stable identifiers such as automation IDs, static HTML ids or data attributes meant for testing.
  • Avoid index attributes unless no other property distinguishes sibling elements.
  • Keep wildcards narrow and anchored to fixed text fragments.
  • Validate against multiple states of the application, such as empty, full and error screens.
  • Test with a different user profile, language and screen scaling before release.
  • Store selectors centrally in an object repository so one fix updates every workflow.

An object repository deserves special attention. When the same login button is referenced in forty workflows, an application update otherwise forces forty separate edits. Central storage turns selector maintenance into a single change and makes version control of interface definitions possible.

Common selector failures and their fixes

Most production incidents in UI automation trace back to a selector that either matches nothing or matches the wrong element. The second case is more dangerous, because the robot continues without an error and may enter data into an unintended field. The table below links typical symptoms to their causes.

SymptomLikely causeRecommended fix
Element not found after an updateChanged id, class or hierarchyRe-target and prefer stable attributes
Works for one user, fails for anotherLanguage-dependent name attributeUse automation ID or role instead
Clicks the wrong row in a gridIndex-based selectorUse a dynamic value from the data
Intermittent timeoutsElement not yet renderedAdd wait conditions for element state
Fails only on a remote desktopNo object tree in the sessionUse a remote runtime agent or OCR
Selector failure symptoms, causes and fixes

Timing problems are often mistaken for selector problems. A correct selector still fails if the robot searches before the element exists or becomes enabled, so selectors should be paired with explicit wait conditions rather than fixed delays.

In simple terms

A UI selector is like a precise address for something on the screen. A person sees a button and simply clicks it, but a software robot needs written directions: which program, which window, which section and which button. The selector holds those directions.

A good address still works when small details change, the way a letter still arrives if a house is repainted. A bad one, such as “the third house on the left”, stops working as soon as a new house is built. Good selectors describe what an element is, not where it happens to sit.

A practical example

A shared services team in a mid-sized manufacturer automates invoice entry into a desktop accounting application. The first version of the robot, created with a recorder, used a selector containing the full window title “Invoice 10452 – Posting” and an index of 7 for the amount field. It worked during testing, but it failed on the first production day because every invoice changed the window title.

The developer rebuilt the selector with a narrow wildcard, Invoice * - Posting, and replaced the index with the field’s automation ID. A month later, a vendor update added a new currency field above the amount, and the robot continued without any change. Over the next quarter, the team processed about 3,000 invoices per month with no selector-related failures, and the selectors were stored in a shared repository that later served two additional workflows.