I have a radio button:
<input type="radio">test</input>
and I would like to retrieve the element by XPath using through its type and the text inside. I have tried the following:
//input[@type='radio' and text() = 'test']
but it hasn’t worked out. I believe the problem is in the text() part since //input[@type='radio'] does select the element.
What is it I’m doing wrong?
In HTML/XHTML,
inputis an empty element; it cannot contain text. In this case, the texttestactually exists as a sibling text node that directly follows theinputelement node, rather than as a text node within theinputelement node. Consequently, the closing</input>tag you have there doesn’t mean anything.Try this instead:
Or this: