I have a table in which I want to get text from a “td” element and below is the xpath I am using. I am getting the td number dynamically based on the th (column header) as I dont want to hardcode. This xpath worked fine when I used SeleniumLibrary but getting error in the Browser Library.
I have the same problem, but in my case in logs showing that I have N elements. But when I paced my XPath with unique value into Chrome DevTools it shows that I have only one match.
Example of xpath: //[contains(@class,‘commonValue’) and contains(@class,‘commonValue2’) and contains(.,‘uniqueValue’)]//[contains(@class,‘commonValue3’)]
As resolving of this problem, I just wrapped my XPath in brackets and take 1st element : (myXpath)[1]
Looks like I already have its ins strict mode. but thanks for hint
Error: locator.elementHandle: Error: strict mode violation: " // div[contains(@class,‘commonValue’) and contains(@class,‘commonValue2’) and contains(.,‘ uniqueValue ’)]//div[contains(@class,‘commonValue3’)]" resolved to N elements:
Hello,
actually since a couple of Browser Library versions (can’t remember when exactly) when you choose a selector that correspond to more than one element in the page, the browser library return this kind of error as it can not choose which of the element you want to interact. Previously, it was selecting the 1st element it found.
Let’s imagine you have a page with several “OK” button, choosing click text=“OK” will return on error as there are many text=“OK” elements in it.
Using strict=False will switch to the old behavior, it will choose the 1st element if there are many in the page, but you must be aware of that of course