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?
tds that have afontwhose text containsShowing" - which is exactly your problem statement! - and you want it to be more concise?!//td[font/text()[.="Showing "]]so I thought there may be a way usingcontainsinstead of=.contains()with Regex, and the expression//td[some $t in font/text() satisfies contains($t, 'Showing')]compared to yours seems "stupidly verbose" to me.