If your selector works on some runs and fails on others, open it and look for an idx attribute. Nine times out of ten, that's the problem.
I see this one on the UiPath Forum constantly, so it was the first thing I wrote up in my Pitfall of the Week series.
Why idx breaks
When you indicate an element and Studio can't tell it apart from similar elements, it adds something like idx='3' to the selector. That works on your screen today. But idx is just the element's position in the UI hierarchy, nothing more.
Add a column to a table, get a popup, or have the page load a little differently, and position 3 is now a different element. Or nothing at all. The robot either clicks the wrong thing or times out, and it looks random because it depends on what the screen looked like on that run.
UiPath's own Workflow Analyzer rule for this, UI-REL-001 (Large Idx in Selectors), says the same thing: the order idx relies on can change when the elements you're automating change, so it should be avoided.
The fix
Open the selector in UI Explorer and replace idx with something that actually describes the element. Good candidates:
aanameidautomationidinnertext
So instead of this:
<webctrl tag='BUTTON' idx='3' />
you'd aim for something like this:
<webctrl tag='BUTTON' aaname='Submit invoice' />
If the stable value changes a bit between runs, use a wildcard. * replaces zero or more characters:
<webctrl tag='SPAN' aaname='Invoice *' />
In Modern activities, add an anchor, meaning a nearby label that never moves, so the target is found relative to something stable. Then keep Fuzzy selector or Image as a fallback targeting method in case the strict selector misses.
A quick check before you publish
Search your project for idx=. Every hit is a possible failure in production.
You can also let Workflow Analyzer do it for you. UI-REL-001 lists every selector with an idx value above the threshold you set, one by one, so you can work through them before they bite.
Docs
- UI-REL-001 Large Idx in Selectors: https://docs.uipath.com/activities/other/latest/ui-automation/ui-rel-001
- Selectors with wildcards: https://docs.uipath.com/activities/other/latest/ui-automation/selectors-with-wildcards
- UI Explorer: https://docs.uipath.com/activities/other/latest/ui-automation/ui-explorer
- Advanced descriptor configuration (strict, fuzzy and image targeting): https://docs.uipath.com/activities/other/latest/ui-automation/advanced-descriptor-configuration
Got a selector horror story? Share it in the original forum thread, that's where the discussion lives: https://forum.uipath.com/t/uipath-pitfall-of-the-week-1-relying-on-idx-in-your-selectors/5783645
Originally posted on the UiPath Forum: https://forum.uipath.com/t/uipath-pitfall-of-the-week-1-relying-on-idx-in-your-selectors/5783645
I post short UiPath fix videos from real forum questions on my YouTube channel, RPA Simplified.
Top comments (0)