UiElement is no longer valid after back button

I am currently scraping a website that has a table with a column full of links with javascript OnClick data. I created a loop to loop through the table and store the links in a collection of UiElement.
This is working correctly.
I then created a foreach loop that loops through the items in the collection and call a click action on the item.
On the first item, the click works as intended. The bot then clicks the back button on the opened website. On the second and all subsequent iterations, the following error is thrown:
The UiElement is no longer valid

I assume this has to do with leaving the page and coming back to the page, but I am not sure. I am very new to UiPath (2-3 weeks of playing around) so it could be something easy I am overlooking.

Any ideas?

Show us what your selector looks like. I’m curious if you have an ID in there that you can replace with a wildcard

Hello @Evan_Watkins - How you are trying to open the second link. Is the bot looking for some page to appear then trying to open. Please explain how the logic built

Hi @Evan_Watkins,

Welcome to community.

Make sure that the selectors you use do not change.

You can get more support if you share the selectors here.


Like @muhammedyuzuak mentioned, most likely your selectors are changing or different when you navigate back to the page.

It could also be that the elements are not yet loaded/active when it is attempting second iteration.

Try these debugging steps:

  • After you build your collection of UIElements, loop through and write the selectors to console. Compare these against the selectors from UIExplorer to determine if the selectors have changed after page navigation.

  • Try adding a delay before clicking on the link. This should give the web app some time to load JavaScript content after the page has stopped loading.

  • Since you are working with a table, you might be able to use idx to click the link on a specific row.

Note: Usage of idx is generally not recommended and should only be used if all other options have been exhausted.