7.3 Dynamic Selectors, Variables & Wildcards in Selectors
Key Takeaways
UiPath selectors are hierarchical XML fragments where Full Selectors contain top-level window/HTML tags and Partial Selectors omit root nodes, relying on container scopes to provide window handles.
UI Explorer provides essential diagnostic capabilities through its Visual Tree, Property Explorer, Selector Editor, and real-time validation and repair utilities.
Wildcard characters—asterisk (
*) for zero or more characters and question mark (?) for exactly one character—enable selectors to tolerate volatile titles, dynamic session IDs, and timestamp mutations.Modern dynamic selectors bind runtime variables directly within XML attribute values using double curly-brace syntax (
{{variableName}}), eliminating error-prone string concatenation.Advanced selector stabilization utilizes regular expression matching (
matching:attribute='regex') and case-insensitivity directives (casesensitive:attribute='false') to handle complex dynamic patterns.
7.3 Dynamic Selectors, Variables & Wildcards in Selectors
Core Concept: At the foundational layer of both Modern and Classic UI Automation sits the XML Selector. A selector is an XML fragment that uniquely identifies a graphical user interface control by cataloging its hierarchical structural attributes within the operating system or browser Document Object Model (DOM). In real-world enterprise automations, static selectors frequently break because target applications generate dynamic session IDs, timestamped window titles, and data-dependent button names. Mastering dynamic selectors, wildcards, and advanced attribute matching is critical for engineering stable, production-grade automations.
When a selector fails, unattended robots stop, transactions fault, and business operations stall. By replacing volatile values with wildcards, injecting runtime variables via modern double curly-brace syntax ({{variableName}}), and leveraging regular expressions (matching:aaname='regex'), developers transform rigid, brittle selectors into resilient, adaptable targeting engines.
1. Selector Syntax and XML Node Architecture
A UiPath selector is composed of one or more hierarchical XML nodes, ordered from the top-level application window down to the specific leaf element:
<wnd app='excel.exe' cls='XLMAIN' title='Quarterly_Report_2026.xlsx - Excel' />
<uia cls='NetUIHWND' name='Ribbon' />
<uia cls='NetUIRibbonButton' name='Save' />
Each line in the selector represents a Selector Node, enclosed in angle brackets (< ... />). A node consists of a Tag and one or more Attributes:
- Tag: Identifies the technical layer or element type (e.g.,
<wnd>for a Win32 window,<html>for a browser page,<webctrl>for an HTML DOM element,<ctrl>for Active Accessibility, or<uia>for UI Automation nodes). - Attribute Name: The property being inspected (e.g.,
app,title,cls,id,name,aaname,tag). - Attribute Value: The expected value required for a match, enclosed in single quotes (e.g.,
tag='BUTTON').
Common Selector Tags and Attributes
| Tag / Attribute | Target Technology | Purpose & Diagnostic Value |
|---|---|---|
<wnd> | Desktop Win32 / WPF | Represents an operating system window. Common attributes: app (executable name, e.g., notepad.exe), cls (window class name, e.g., Notepad), title (window title bar text). |
<html> | Web Browser | Represents an active web browser tab. Common attributes: app (e.g., chrome.exe, msedge.exe), title (HTML <title> tag), url (web page address). |
<webctrl> | Web DOM Element | Represents an HTML element inside a browser. Common attributes: tag (INPUT, BUTTON, DIV, TABLE), id, name, aaname (Active Accessibility name / visible label), class. |
<ctrl> | Win32 / MSAA | Microsoft Active Accessibility node. Common attributes: role (push button, editable text, menu item), name. |
aaname | Multi-technology | "Active Accessibility Name". Represents the human-readable text label of an element. Highly valuable for buttons, links, and headers. |
idx | Multi-technology | Ordinal numerical index (e.g., idx='3'). Warning: Represents the element's position among identical siblings. Highly volatile and discouraged in production automations. |
2. Full Selectors vs. Partial Selectors
Understanding the distinction between Full Selectors and Partial Selectors is fundamental to designing maintainable workflows:
+-----------------------------------------------------------------------------------+
| FULL SELECTOR (Standalone Execution) |
| |
| <html app='chrome.exe' title='ACME System 1 - Dashboard' /> <-- Root Window |
| <webctrl tag='BUTTON' id='btn_logout' aaname='Log Out' /> <-- Leaf Target |
| |
| - Contains the top-level window/browser node. |
| - Can execute independently outside any container. |
+-----------------------------------------------------------------------------------+
+-----------------------------------------------------------------------------------+
| PARTIAL SELECTOR (Container-Bound Execution) |
| |
| Container: Use Application/Browser Scope |
| Container Selector: <html app='chrome.exe' title='ACME System 1 - Dashboard' /> |
| │ |
| └── Activity: Click |
| Partial Selector: <webctrl tag='BUTTON' id='btn_logout' aaname='Log Out' /> |
| |
| - Omits root window node; inherits window handle (HWND) directly from container. |
| - Faster execution, centralized window title management. |
+-----------------------------------------------------------------------------------+
Architectural Comparison
| Evaluation Metric | Full Selector | Partial Selector |
|---|---|---|
| Root Node Presence | Contains top-level <wnd> or <html> node. | Omits top-level window tags; starts directly at child/element level. |
| Container Requirement | Can execute standalone; does not require an enclosing container activity. | Must reside inside a container activity (Use Application/Browser, Attach Window, Attach Browser). |
| Execution Performance | Slower: Must search the entire desktop OS visual tree to locate the window on every action. | Faster: Container caches the application's window handle (HWND); child activities query within that window handle directly. |
| Maintenance Overhead | High: If an application window title changes, every single activity selector must be updated. | Low: Update the window selector once on the parent container; all nested partial selectors inherit the update. |
| Multi-Window Handling | Can jump between completely different applications in sequential activities without containers. | Bound to the application context defined by the enclosing scope. |
3. Tuning Selectors in UI Explorer
UI Explorer is UiPath's advanced diagnostic and tuning utility for inspecting the application hierarchy and constructing robust selectors.
+---------------------------------------------------------------------------------------+
| UI EXPLORER |
| |
| [VISUAL TREE PANEL] [SELECTOR EDITOR PANEL] |
| ├── wnd app='chrome.exe' <html app='chrome.exe' title='Invoicing' /> |
| │ └── ctrl name='Document' <webctrl tag='INPUT' id='inv_num' /> |
| │ ├── webctrl tag='FORM' |
| │ └── webctrl tag='INPUT' [VALIDATE BUTTON] -> [State: Green (Valid)] |
| |
| [PROPERTY EXPLORER PANEL] [SELECTED ATTRIBUTES PANEL] |
| aaname = "Invoice Number" [*] tag = 'INPUT' |
| id = "inv_3948293" [ ] id = 'inv_3948293' <-- Dynamic! Deselect |
| class = "form-control input" [*] aaname = 'Invoice Number' <-- Stable! Select |
| visibleinnertext = "" [*] name = 'invoiceNumber' |
+---------------------------------------------------------------------------------------+
Key Panels and Operational Utilities in UI Explorer:
- Visual Tree (Left Panel): Displays the entire hierarchical object model of the desktop or DOM. Developers can navigate up to parent containers or drill down into child nodes, identifying parent wrappers that offer more stable structural attributes.
- Property Explorer (Lower-Left Panel): Catalogs every single UI property exposed by the selected control (including accessibility properties, DOM attributes, bounding coordinates, and visibility flags). This allows developers to discover hidden, stable identifiers that Studio did not select automatically.
- Selector Editor (Top-Right Panel): The working area where the active selector is constructed. Attributes can be edited directly, wildcards inserted, or variable bindings defined.
- Validation States:
- Green Checkmark (Valid): The selector successfully and uniquely identifies exactly one active UI element on screen.
- Red Cross (Invalid): The selector cannot find any matching element on the active desktop.
- Yellow Warning (Changed): The selector was manually edited and requires revalidation by clicking the Validate button.
- Indicate Element & Repair:
- Indicate Element: Allows re-pointing to a different UI control.
- Repair: If a target application layout changes and breaks a selector, clicking Repair prompts the developer to click the element on screen again. UiPath compares the old selector with the new element's attributes and automatically updates attributes with wildcards or new stable tags.
- Highlight: Flashes a high-visibility colored bounding box around the element identified by the selector, allowing visual confirmation that the selector matches the intended target rather than a hidden sibling.
4. Wildcards in Selectors
When applications incorporate dynamic elements—such as window titles containing changing document names, web pages with session IDs, or timestamps—static selectors fail. UiPath provides two essential wildcard operators to handle dynamic character sequences:
1. The Asterisk (*) Wildcard
- Definition: Matches zero or more arbitrary characters.
- Example 1 (Window Title): An application window displays the current document name:
title='Monthly_Report_January_2026.xlsx - Excel'. In February, this becomesMonthly_Report_February_2026.xlsx. Replacing the dynamic month with an asterisk stabilizes the selector:<wnd app='excel.exe' cls='XLMAIN' title='Monthly_Report_*_2026.xlsx - Excel' /> - Example 2 (Dynamic Web URL / Session ID): A web portal generates unique session IDs in its element IDs (
id='submit_btn_session_94820384'):<webctrl tag='BUTTON' id='submit_btn_session_*' aaname='Submit' />
2. The Question Mark (?) Wildcard
- Definition: Matches exactly one arbitrary character.
- Example (Fixed-Length Version or Page Code): An enterprise dashboard uses single-digit page indicators or fixed-format document codes (e.g.,
Doc_V1,Doc_V2):
This matches<webctrl tag='DIV' aaname='Doc_V?' />Doc_V1andDoc_V2, but will not matchDoc_V10(which contains two characters followingV).
Caution
Avoid Overusing Wildcards: Replacing too many attributes with asterisks (such as <webctrl tag='*' aaname='*Submit*' />) causes selector ambiguity. If multiple elements match the wildcard pattern, the robot will either interact with the wrong element or throw an ambiguity exception. Always preserve static tags (tag='BUTTON') and container anchors.
5. Dynamic Selectors Using Variables and Arguments
In transactional processes, robots must frequently interact with specific UI elements determined at runtime—such as clicking a table row corresponding to in_TransactionItem.SpecificContent("InvoiceID").ToString or selecting an account from a dropdown list.
In Modern UiPath Studio, developers parameterize selectors using double curly-brace syntax: {{variableName}} or {{argumentName}}.
<!-- Targeting a dynamic customer row in an enterprise CRM table -->
<webctrl tag='TABLE' id='customers_grid' />
<webctrl tag='TD' aaname='{{in_CustomerName}}' />
Step-by-Step Parameterization in Studio:
- Open the activity's Target selector in the Selector Editor.
- Highlight the attribute value to parameterize (e.g.,
aaname='John Doe'). - Right-click the highlighted text and choose Create Variable (or select an existing variable/argument from the context menu).
- Studio automatically formats the attribute as
aaname='{{in_CustomerName}}'. - At runtime, the robot dynamically evaluates the variable's current value in memory and injects it into the XML selector before querying the application tree.
Modern Variable Binding vs. Classic String Concatenation
In legacy Studio projects, dynamic selectors required cumbersome, unreadable VB string concatenation directly in the Properties panel:
' Legacy Classic Concatenation (Fragile and Error-Prone):
"<webctrl tag='BUTTON' aaname='" + in_CustomerName + "' />"
Modern double curly-brace syntax (aaname='{{in_CustomerName}}') is directly supported inside the visual Selector Editor, supports syntax validation, and prevents syntax errors caused by missing quotes or concatenation operators.
6. Advanced Selector Matching: Regular Expressions & Case Sensitivity
For complex dynamic patterns that exceed simple wildcards, UiPath supports advanced selector matching directives.
1. Regular Expression Matching (matching:attribute='regex')
To match attributes adhering to complex alphanumeric patterns—such as formatted invoice numbers, UUIDs, or email addresses—developers activate regex matching by prepending matching:attributeName='regex' to the selector node:
<!-- Matching an invoice label with pattern: INV- followed by exactly 6 digits -->
<webctrl tag='SPAN' matching:aaname='regex' aaname='^INV-\d{6}$' />
Practical Regex Selector Examples:
- Alphanumeric Purchase Order Code:
<webctrl tag='INPUT' matching:id='regex' id='^po_(alpha|beta)_[0-9]{4}$' /> - Dynamic Subdomain or URL Routing:
<html app='chrome.exe' matching:url='regex' url='https://(dev|uat|prod)\.acme\.com/dashboard' />
2. Case Sensitivity Directives (casesensitive:attribute='false')
By default, selector attribute matching in web and desktop applications is case-sensitive. If an application's backend randomly renders aaname='SUBMIT' in uppercase on some screens and aaname='Submit' in title case on others, a strict selector fails.
Developers override this behavior using the casesensitive directive:
<!-- Case-insensitive matching for a submit button -->
<webctrl tag='BUTTON' casesensitive:aaname='false' aaname='submit' />
This matches Submit, SUBMIT, submit, or sUbMiT seamlessly.
7. Common Selector Pitfalls and Enterprise Best Practices
- The
idxAnti-Pattern:- Pitfall: Using
idx(e.g.,<webctrl tag='INPUT' idx='4' />). Anidxattribute simply indicates that this is the 4th input tag found in the tree. If the web page displays an alert banner or adds a single field above,idx='4'silently shifts to a completely different field, causing the robot to enter data into the wrong control. - Remedy: Eliminate
idxby adding stable attributes (aaname,name,automationId) or binding the target to an Anchor.
- Pitfall: Using
- Dynamic Framework Hashes and GUIDs:
- Pitfall: Relying on autogenerated IDs produced by modern web frameworks like React, Angular, or Blazor (e.g.,
id='btn_j_id_jsp_4920492'orclass='button-primary ng-tns-c45-12'). These tokens change every time the application is rebuilt or the user refreshes the page. - Remedy: In UI Explorer, uncheck volatile
idandclassattributes. Replace them with stable semantic attributes liketag='BUTTON'andaaname='Save', or use wildcards (id='btn_*').
- Pitfall: Relying on autogenerated IDs produced by modern web frameworks like React, Angular, or Blazor (e.g.,
- Fragile Window Titles:
- Pitfall: Recording window titles that include dynamic file paths, document names, or timestamps without wildcards (e.g.,
title='Report_2026-09-29_1400.pdf - Adobe Acrobat'). - Remedy: Wildcard the dynamic suffix:
title='Report_* - Adobe Acrobat'.
- Pitfall: Recording window titles that include dynamic file paths, document names, or timestamps without wildcards (e.g.,
- Prefer Partial Selectors within Containers:
- Best Practice: Always nest UI interactions inside
Use Application/Browsercontainers using Partial Selectors. This isolates top-level window changes to a single container activity and maximizes runtime execution speed.
- Best Practice: Always nest UI interactions inside
A developer needs to configure a selector node to match an invoice identifier that always starts with "INV-" followed by exactly six numeric digits (for example, "INV-109284"). How should this attribute be defined in the XML selector?
<webctrl tag='SPAN' aaname='INV-??????' wildcard:aaname='true' />
<webctrl tag='SPAN' matching:aaname='regex' aaname='^INV-\d{6}$' />
<webctrl tag='SPAN' aaname='INV-*' casesensitive:aaname='regex' />
<webctrl tag='SPAN' matching:aaname='fuzzy' threshold='6' />
What is the primary architectural and operational difference between a Full Selector and a Partial Selector in UiPath Studio?
Full selectors only support desktop applications, while partial selectors are restricted to web browsers.
Partial selectors can only be authored in C# workflows, whereas full selectors are required for VB.NET.
A Full Selector contains the top-level window node and can execute independently, whereas a Partial Selector omits top-level window tags and must execute inside a container activity that provides the window context.
Full selectors execute faster because they bypass Windows operating system accessibility APIs entirely.
When inspecting an auto-generated selector in UI Explorer for an input field on an enterprise web form, a developer observes the attribute id='txt_usr_8492049' along with idx='2'. What is the most effective approach to stabilize this selector for production deployment?
Deselect the volatile autogenerated id and fragile idx attributes in UI Explorer, replace them with stable semantic attributes like aaname, and bind the target to a static visual anchor.
Increment the idx attribute to idx='3' to ensure forward compatibility with form changes.
Enclose the entire selector in a TryCatch block set to retry 50 times in a loop.
Change the selector tag from webctrl to wnd and force Hardware Events input mode.
Sections you finish are checked off in the contents.