Error in 'For Each UI Element' Activity - "UI element is invalid"

HI,
I am pretty new to UiPath and I’m experiencing an issue with the ‘Click’ activity in UiPath while looping through Salesforce records. It is a part of a ‘For each UI element’ activity, but only loops through the records once, i.e. only clicks on the first record of the list and then throws this error:
Click: The UI element is invalid. Make sure the target application is open and the element is on the screen.
When I tried it with the ‘Highlight’ activity, it works.

Any thoughts on what the issue would be here?
Thanks!

@Slavica_Stojmenova,

This could be faced if the Ui Element is not visible on screen.

Solution: Check Visibility and Scroll

Ensure that each element is brought into view before attempting to click.
Use the ‘Scroll To Element’ activity before the ‘Click’ activity to ensure the element is visible.

Thanks,
Ashok :slight_smile:

Thanks for the feedback, but it is still the same error. And also I don’t think that is the problem since I have everything visible on the page.

Please check whether same window/tab is opened on another browser tab or window, if yes then close and run on only one window.

@Slavica_Stojmenova

Try these steps which I got while research on this problem:

1. Ensure the Target Application is Stable

Make sure that the Salesforce application is stable and that the records are fully loaded before the robot tries to click on them. You can use activities like Element Exists or On Element Appear to ensure that the UI elements are available before performing the click action.

2. Dynamic Selectors

The issue might be due to static selectors which only point to the first record. You need to make sure that the selector used for the Click activity is dynamic and can adapt to each record in the loop. Here’s how you can do it:

  • Use UI Explorer: Open UI Explorer and examine the selector for the record element. Identify the part of the selector that uniquely identifies each record.
  • Variables in Selectors: Replace the unique part of the selector with a variable that changes with each iteration of the loop.

3. Anchor Base

If the elements are not uniquely identifiable, use an Anchor Base activity. This activity allows you to use a stable element near your target element as an anchor to improve the accuracy of the selector.

4. Add Delays

Adding slight delays can sometimes help to ensure that the application has caught up with the automation. You can add Delay activities within the loop to give the application time to render the elements properly before the next click.

5. Check Element Visibility

Ensure that the target element is visible and not covered by other elements or scrolled out of view. You can use activities like Scroll Down or Send Hotkey (e.g., Page Down) to bring the element into view if it is not visible.

6. Retry Scope

If the click is sometimes missing due to timing issues or transient UI states, consider wrapping the Click activity inside a Retry Scope. This can retry the click operation a few times before failing.

It appears to me that your replies seem to be largely AI generated, please follow the guidelines on using an LLM for making an answer and start citing the tools you are using in generating your replies.

Guidance is here.
https://forum.uipath.com/faq#llm

here is an example of how it works, make sure you’re not clicking the items as they are hyperlinks and will open another webpage and thus breaking automation if not handled corectly
https://uipath-my.sharepoint.com/:v:/p/gabriel_tatu/ETNWkbU51pBBlvPx9RUfl1cBSIVtxpmHs1C1cQ1h9zZAew?e=9iK4iS

1 Like