DEV Community

Pravinraj Vincent
Pravinraj Vincent

Posted on Originally published at forum.uipath.com

UiPath Pitfall #1: Relying on idx in Your Selectors

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:

  • aaname
  • id
  • automationid
  • innertext

So instead of this:

<webctrl tag='BUTTON' idx='3' />
Enter fullscreen mode Exit fullscreen mode

you'd aim for something like this:

<webctrl tag='BUTTON' aaname='Submit invoice' />
Enter fullscreen mode Exit fullscreen mode

If the stable value changes a bit between runs, use a wildcard. * replaces zero or more characters:

<webctrl tag='SPAN' aaname='Invoice *' />
Enter fullscreen mode Exit fullscreen mode

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

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)