Sarah
Sarah

Reputation: 87

How to get the element count matching text in nth column of Span Table

Col1     Col2   Col3    Col4    Col5

  2     XYZ    Andy     Div2    Address2

  3     NNN    Spencer  Div1    Address3

  4     YYY    Krish    Div8    Address4

  5     ABC    Sima     Div1    Address5

I have a span table like the one in the above example, and I'm trying to get the count of cells matching text Div1 in the 4th column (Col4). I tried the below code and got an error (invalid xpath locator):

${RecordCount}= Get Matching Xpath Count //td[4][matches(text(),'Div1')]

Upvotes: 3

Views: 955

Answers (2)

thanh le
thanh le

Reputation: 300

From the SeleniumLibrary document it says that the Get Matching Xpath Count keyword is DEPRECATED in SeleniumLibrary 3.2. Use Get Element Count instead. So you should try to use "Get Element Count" keyword instead. The error you mentioned means your input xpath is wrong. Probably try this xpath=//td[text()="Div1"]

Upvotes: 2

Todor Minakov
Todor Minakov

Reputation: 20067

The issue is because of the matches() function - it is present in XPath 2.0, while all the browsers support only v1.0; thus the error the locator is invalid.

Just change it to contains() and it'll work for you:

//td[4][contains(text(),'Div1')]

Upvotes: 3

Related Questions