Find UI Elements With Wildcard Selectors and Label Anchors
Last updated: November 29, 2026
Quick Overview
Given a UI element tree (tag, attributes, children), a hierarchical selector where each step matches a descendant of the previous match using * and ? wildcards in attribute values, and an optional anchor spec, return the matching target elements. When an anchor is given, keep only targets whose nearest matching sibling is closest, preferring a label that precedes the field.
UiPath
November 29, 20260
0
0 solved
Given a UI element tree (tag, attributes, children), a hierarchical selector where each step matches a descendant of the previous match using * and ? wildcards in attribute values, and an optional anchor spec, return the matching target elements. When an anchor is given, keep only targets whose nearest matching sibling is closest, preferring a label that precedes the field.
UI Automation in Studio identifies controls through selectors and anchors so that robots keep working when window titles change or several identical text boxes sit on one form. An onsite coding round in this style checks tree traversal, careful matching semantics, and how a candidate resolves ambiguity in a way users would expect.
What the Interviewer Expects
- Clarifies descendant versus direct-child semantics and wildcard rules
- Separates node matching from traversal for readability
- Avoids returning duplicates when two frontier nodes share descendants
- Implements anchor scoring with an explicit, explained tie-break
- Uses iterative traversal or acknowledges recursion depth on deep trees
- Analyzes cost in terms of tree size and selector length
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you score fuzzy matches instead of exact wildcard matches, and pick the best target?
- Anchors in real screens are spatial, not sibling order. How would you use bounding boxes?
- The tree has 50,000 nodes and selectors are evaluated thousands of times a run. What would you cache or index?
- How would you report to the user why a selector matched zero or several elements?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
A node is {"tag", "attrs", "children"}. A selector is a list of specs {"tag": pattern, "attrs": {key: pattern}}; step i must match some descendant of a node matched by step i-1 (step 0 searches be...
High-Level Design
node_matcheschecks tag and every required attribute withfnmatchcase.- Build a parent map once so anchors can look at siblings.
- Walk the selector as a frontier: for each step, collect mat...