Let's say I have a piece of HTML like this:
<a>Ask Question<other/>more text</a>
I can match this piece of XPath:
//a[text() = 'Ask Question']
Or...
//a[text() = 'more text']
Or I can use dot to match the whole thing:
//a[. = 'Ask Questionmore text']
This post describes this difference between .
(dot) and text()
, but in short the first returns a single element, where the latter returns a list of elements. But this is where it gets a bit weird to me. Because while text()
can be used to match either of the elements on the list, this is not the case when it comes to the XPath function contains()
. If I do this:
//a[contains(text(), 'Ask Question')]
...I get the following error:
Error: Required cardinality of first argument of contains() is one or zero
How can it be that text()
works when using a full match (equals), but doesn't work on partial matches (contains)?