Avoid selecting wrong element when identical elements present?

Hi,

The site has these elements present where the 4 or all boxes are identical:
image

I select this one:
image

I would like to know the technicals behind what makes the selector work in some cases when the target box is missing and sometimes does not:
image

Still works but selecting the wrong box:
image

Does not work:
image

I achieved this by disabling the elements in the developer panel(devtools/F12) in Edge.

Im asking this because I would like to know how can one be certain that the robot for example will not type in stuff in the wrong box in real life scenarios?

Use UiExplorer and look at the selectors of each of the boxes. See which attribute makes each box unique from each other

It looks like a complex UI, but @atomic you need to Check all the elements and Identify which is best for you, I can give you a solution when I can review the same but in your case, I can’t.

You get the solution but you need to understand the below best practices for selectors for window-based applications.

Uniqueness is Key:

  • Strive to create selectors that uniquely identify the target element. This reduces the risk of unintended selection.
  • Prioritize attributes like id, aaname (automation ID), or name if they hold unique values.
  • If these attributes aren’t unique, consider using a combination of attributes or leveraging positional information (idx).

Example (Unique id):

XML<webctrl aaname='' tag='INPUT' type='text' id='unique_text_box' />

Example (Combining Attributes):

XML<webctrl aaname='' tag='INPUT' type='text' class='common_class' idx='2' />

Relative Selectors (with Caution):

  • Use relative selectors with care, as they can become brittle if the UI structure changes.
  • If you must use them, ensure a stable parent element and avoid relying solely on positional information.

Example (Relative Selector):

XML<webctrl aaname='' tag='INPUT' type='text' parentid='unique_parent_element' />

Leverage UiPath Studio Features:

  • UiExplorer: Visually inspect the UI structure and identify unique attributes.
  • “Induce Element” Feature: Right-click an element and select “Induce Element” to generate more robust selectors.

Handle Dynamic Elements (if applicable):

  • If elements are dynamically generated, explore using idx cautiously or consider alternative approaches like waiting for specific content to load before selecting.

Additional Tips:

  • Wildcards (*): Use wildcards sparingly, as they can broaden the match criteria and potentially select unintended elements.
  • Custom Properties : Define custom properties to store dynamic values for selector construction.
  • Error Handling: Implement robust error handling to catch situations where the target element cannot be found.

Note: Idx selector is not recommended.

Thanks for your answer @mukesh.singh but I am not the one asking the question…

Try to use strict selector and give the unique attribute which u can get it from UI Explorer