What XPath to select only non-taged text inside div. Selenium. Java
15,598
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/>
.
Author by
Andrzej Rehmann
“It would seem that you have no useful skill or talent whatsoever," he said. "Have you thought of going into teaching?”
Updated on June 04, 2022Comments
-
Andrzej Rehmann about 2 years
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.