Search code examples
xpathrobotframeworkselenium2library

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')]


Solution

  • 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')]