I am coding some Perl to use XPath to search for a specific item tdin a table "that looks like this
<table>
<tr>
<td>...</td>
<td><font color="white" face="verdana, Helvetica, Arial" size="2">Showing <b>1</b>-<b>100</b> of <b>200</b> total</font></td>
<td>...</td>
<td>...</td>
</tr>
</table>
I want to find an element tdthat has a font/text()node that contains a string Showing.
corresponds to contains(., "Showing")
Direct comparison works fine:
//td[font/text()="Showing "]
but I want to use the contains()XPath function to make the match more flexible.
I tried
//td[contains(font/text(), "Showing ")]
but it causes an error
XPath failed due to: A sequence of more than one item is not allowed as the first argument of contains()
and I managed to achieve what I want with
//td[font/text()[contains(., "Showing")]]
but it is very ugly, and I hope for something more concise. Please, can someone improve this for me or perhaps confirm that this is the best and most concise way?
source
share