Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath - select text after certain node

Tags:

xpath

I have found a node, now i need to select sibling text after it:

enter image description here

In my case i need to get the text : 10 January

How do i do this?

like image 696
warvariuc Avatar asked Jan 11 '12 10:01

warvariuc


People also ask

How do I select text in XPath?

Do note that /html/text() doesn't select all text nodes in the document -- only the text nodes that are children (not descendents) of the top, html element. You probably want /html//text() . Some knowledge and understanding of XPath is typically required in order to construct XPath expressions. Thanks.

What is text () in XPath?

XPath text() function is a built-in function of the Selenium web driver that locates items based on their text. It aids in the identification of certain text elements as well as the location of those components within a set of text nodes. The elements that need to be found should be in string format.

What is XPath selector?

XPath stands for XML Path Language. It uses a non-XML syntax to provide a flexible way of addressing (pointing to) different parts of an XML document. It can also be used to test addressed nodes within a document to determine whether they match a pattern or not.


1 Answers

Try this:

//foo/following-sibling::text()[1]

(replace //foo/ with your current XPath expression.

With this XML:

<data> <foo>foo</foo> bar <baz>baz</baz> </data> 

it gives bar as output.

like image 198
Lasse Espeholt Avatar answered Sep 27 '22 15:09

Lasse Espeholt