I recently have problems with my test suite using Browser lib,
I frequently use get elements keyword to retrieve a list of elements. Then I perform a FOR loop on it to click on each element of the list
something like :
${element list} = get elements <my selector>
FOR ${Element} IN @{element list}
click ${element}
END
I have recently upgraded my robot + browser versions to latest one (and this is leading to some errors. It happens that one of the click failed as it can not find the element : (waiting for selector “button.filter-active .mericon-close >> nth=2” …)
to complement my question the workaround that I have identified is to do something like :
${element count} = get element count <my css selector>
FOR ${index} IN RANGE ${element count}
${element list} = Get elements <my css selector>
click ${element list} [0]
END
this will make refresh the DOM element list every iteration of the loop
not very nice but did not find any other idea
Interesting that you did have to modify the usage of the library. There is difference starting from release 10 that moved to use Playwright Locators instead of pointing to ElementHandles. Locators are resolved only when they are used, but that example should work in similar manner.
I finally got it …
In my UI under test, there are list of object with a delete button in each
My test get all these delete button from all the elements using the get elements with the correct locator
It then loop on the list of element and click on it
So the DOM element disappear from the page after the click and I think that the element list retrieved at the beginning is no more accurate.
It used to work before release 10 as ElementHandles did not changed but if now resolution is dynamic this does not work anymore
in situations where you are deleting/removing things from a list, I find it’s best to work from the bottom up, i.e. get the count, action the last and decrement the count, that way the item numbers don’t change and the number item you want to action still exists (only the ones after that have been removed.