Rich Stevens Rich Stevens - 1 year ago 80
HTML Question

Grab following siblings in XPath?

I am trying to grab the

class text in the following based on the strong tag higher up in the tree containing a certain word, in this case: "restaurants":

<p class="">The location, where the condo is situated,
offers a good choice of <strong>restaurants</strong>.
Some of them are listed below:</p>
<ul class="">
<li class="">Restaurant 1</li>
<li class="">Restaurant 2</li>
<li class="">Restaurant 3</li>
<li class="">Restaurant 4</li>
<li class="">Restaurant 5</li>

I have tried many variations of the following, assuming that I need to go higher up the tree by using "ancestors":


Answer Source

This XPath,

//p[strong = 'restaurants']/following-sibling::ul[1]/li

will select all li elements of the first ul element following sibling of the p element that contains a strong element whose string value is "restaurants".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download