This simple XPath expression,
//a[contains(., 'Link')]
will select the a
elements of all of your examples because .
represents the current node (a
), and contains()
will check the string value of a
to see if it contains 'Link'
. The string value of a
already conveniently abstracts away from any descendent elements.
This even simpler XPath expression,
//a[. = 'Link']
will also select the a
elements in all of your examples. It's appropriate to use if the string value of a
will exactly equal, rather than just contain, "Link"
.
Note: The above expressions will also select <a href="blah">Li<br/>nk</a>
, which may or may not be desirable.
nk` and `Link` so it's safer to use `text()` in my opinion... – Josh Crozier Feb 10 '16 at 20:53