I am coding some Perl to use XPath to locate a particular td
element within a table` that looks similar to 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>
What I want is to find a td
element that has a font/text()
node that contains the string Showing
.
matches contains(., "Showing")
A direct comparison works fine:
//td[font/text()="Showing "]
but I want to use the contains()
XPath function so that the match is more flexible.
I have tried
//td[contains(font/text(), "Showing ")]
but this raises the error
XPath failed due to: A sequence of more than one item is not allowed as the first argument of contains()
and I have managed to achieve what I want with
//td[font/text()[contains(., "Showing")]]
but this is very ugly and I am hoping for something more concise. Please can someone improve on this for me, or perhaps confirm that this is the best and most concise way?
Try this:
//td[contains(font/text()[1], 'Showing ')]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With