I guess you can't use text()
here. Because this function returns a sequence of child text nodes of current span
element. There are 2 text nodes in your example:
<span>
<input type='radio'/>
option1
</span>
1st text node is between <span>
and <input type='radio'/>
containing just a newline.
2nd text node is between <input type='radio'/>
and </span>
containing option1
text plus 2 newlines (at the begining and at the ending).
contains
function expects a string argument instead of a sequence. I think it will take only first text node from the sequence, which contains just a newline.
If you need to select input
followed by some text
node you can use the following expression:
//input[@type='radio'][contains(following-sibling::text(), 'option1')]
If you need to select span
containing text option1
and input
with @type='radio'
, you can try the following expression:
//span[contains(., 'option1') and input/@type='radio']
If you need to select input
instead of span
then use the following expression:
//span[contains(., 'option1')]/input[@type='radio']
I can suggest you the following resources to gain some information about XPath. W3C recomendations contains a full description of XPath. If you use XPath 2.0 then you can look at:
For XPath 3.0 look at:
These recomendations are big enough and hard to read. But you can find in these documents a list of all available axes including following-sibling::
, a description of text()
, a description of contains()
, etc.
Also there are a lot of brief XPath tutorials. For example you can look at this one.