2

I am trying to grab the li 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>
</ul>

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

//ul/li[contains(ancestor-or-self::@strong[contains(text(),'Restaurants')])
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Rich Stevens
  • 599
  • 4
  • 17

1 Answers1

0

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".

kjhughes
  • 106,133
  • 27
  • 181
  • 240