Best Practices For Building Good Selectors

Is there a best practice for creating selectors so they continue to work when a website is updated?

The hardest part of development is to ensure you have strong selectors in place. Good selectors minimize impacts when the element Robot interacts with changes its appearance or position on the screen.

Following guidelines helps in building resilient selectors while minimizing the impact when there are changes:

  1. Use UiPath Explorer and go through the visual tree to strengthen your variable
  2. Use aaname attribute of the selector matching with the visible name or label of the fields
  3. Use variables when the element name changes dynamically based on data input
  4. Avoid using class attributes if possible
  5. Do not use css-selectors or any attributes related to the styling of the page (to avoid impact to the Robots due to any appearance changes)
  6. Do not use idx attribute - this is a dynamic variable and changes depending on the time the element loads on the page
  7. Do not use OCR for selectors unless there is no other option
  8. Use Attach browser or attach window Activities to minimize the number of changes to top-level selectors
  9. Use Browser variable input instead of hardcoded selectors in the attach browser activity
  10. Library for UI Interaction of the application: if the application involved frequently changes the UI, consider building the Library and add all the Activities which interact with the UI of that application in it. This way when there are changes to the UI, update the library and reference the new version of it in the dependencies of the UiPath Project using this application.

4 Likes