Browser Library: Getting "strict mode violation: resolved to 2 elements" issue when using Get Text

HI all,

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.

Xpath used:

//table[@aria-label=‘table’]//tr[1]/td[count(//table[@aria-label=‘table’]//span[text()=‘Host Name’]//parent::th/preceding-sibling::th)+1][@class=‘MuiTableCell-root MuiTableCell-body’]

Below are the logs: I need to use the first element.

waiting for selector “xpath=//table[@aria-label=‘table’]//tr[1]/td[2]”
strict mode violation: “xpath=//table[@aria-label=‘table’]//tr[1]/td[2]” resolved to 2 elements:
1) CDLEN015 aka playwright.$(“text=CDLEN015”)
2) 1 aka playwright.$(".patching-history-table .MuiPaper-root .MuiTable-root .MuiTableBody-root tr td:nth-child(2)")

Could some one please help.

Could some one please help?

Hi Rudy,
There are now 2 elements returned in the logging, But I Think you need to make definition of the xpath unique?

Hi JoostW,
yes how to do it is my question. I have only class name attribute for “td” elements and its same and I need to get text for this xpath

Hi Rudy,

Do you have an example of the DOM structure?