Issue
I want to select only the text "only this text" from the snipet below using XPath (in Java) but that text is random and I don't know what is written there.
<div class="A">
<input id="button" type="button">x</input>
only this random text
</div>
What is the simplest xpath?
//div[@class='A'][what next?]
I saw similar questions but answers are always too complicated and I would like to know the simplest way.
Also is there any other way, without using XPath (in Java),to get that text?
Thanks.
Solution
You can select text nodes using the axis step text()
.
//div[@class='A']/text()
If you only want text nodes following the <input/>
node, use this:
//div[@class="A"]/input/following-sibling::text()
You can add arbitrary predicates to the <input/>
element, too - like you did for the <div/>
.
Answered By - Jens Erat
Answer Checked By - Timothy Miller (JavaFixing Admin)