FenrisL
FenrisL

Reputation: 287

XPath: Get next element where parent contains text

<h3>2.2 Header Text</h3>
<dl>
 <dd>Text 1</dd>
</dl>

I have the following html code and i need to get the text between the "dd" element where the h3 tag above it contains the text "2.2".

For now I have tried the following xpath to find the h3 tag that contains this text

//h3[contains(text(),'2.2')]

but I can't figure out how to get the elements below in order to get the dd element. How could i achieve that?

Upvotes: 1

Views: 1004

Answers (1)

Prophet
Prophet

Reputation: 33361

Please try this:

//h3[contains(text(),'2.2')]/following-sibling::dl/dd

For more details see this discussion

Upvotes: 1

Related Questions