Mitch Dale When working with repeated HTML elements in Web RPA, it’s easy to assume that :nth-of-type() will select the nth matching element on the page. However, that’s not how the selector works, and this mismatch is what causes the behaviour you’re seeing.
:nth-of-type() works relative to an element’s siblings, not relative to how many elements match your selector.
In your case, each span is the first (and only) span inside its own parent, so every one of them is :nth-of-type(1). That’s why this selector, span[data-role="cm-entitylist-Client-launch-Accounting"]:nth-of-type(1) matches all of the elements, and :nth-of-type(2) never matches anything.
Here is some simplified HTML showing this:
<div class="row">
<span data-role="cm-entitylist-Client-launch-Accounting">Client A</span>
</div>
<div class="row">
<span data-role="cm-entitylist-Client-launch-Accounting">Client B</span>
</div>
<div class="row">
<span data-role="cm-entitylist-Client-launch-Accounting">Client C</span>
</div>
Each span is the first span inside its own .row, so they are all span:nth-of-type(1).
The correct approach, apply nth-of-type() to the repeating parent
To loop through the elements you need to apply :nth-of-type() to the repeating container/parent element then select thespan inside it. For example:
div.row:nth-of-type(1) span[data-role="cm-entitylist-Client-launch-Accounting"]
div.row:nth-of-type(2) span[data-role="cm-entitylist-Client-launch-Accounting"]
div.row:nth-of-type(3) span[data-role="cm-entitylist-Client-launch-Accounting"]
Now nth-of-type() is counting rows instead of spans, which allows each element to be uniquely targeted.