Using Robot Framework with Playwright: I'm needing to find and interact with an element on a webpage, but the element does not have an ID nor a unique class name, due to it being a re-used item that we generate different versions of through different cards.
The DOM would show:
<div class="reused class name"> Card 1 </div>
<div class="reused class name"> Card 2 </div>
<div class="reused class name"> Card 3 </div>
<div class="reused class name"> Card 4 </div>
And say I wanted the robot to find Card 3 and click on it. But, perhaps another day there will be a "Card 2.5" and "Card 1.75". Which blocks xpath since it might not always be the third item.
I can't seem to find anything straightforward that would identify the Content tag for the element, since that is the unique identifier of the element. I'm sure there is something easy I'm missing, I've tried thinking through a For loop to iterate over all elements but that's when things get messy.
You can search for an element with both the class and the element text, with something like this:
xpath=//div[@class='reused class name' and contains(text(), 'Card 3')]
A better solution would be to go back to your developers and ask them to provide a unique attribute for each div.