StevieD
StevieD

Reputation: 7443

XPath syntax for getting nodes after another node?

I have something like this:

<div id = "colors">
   <div id = "color_red"  ></div>
   <div id = "color_blue" ></div>
   <div id = "color_green"></div>
   <div id = "color_black"></div>
   <!-- and so on -->
</div>

I'm trying to select all the divs after the color_blue div with:

//div[@id="colors"]/following-sibling::div[@id="color_blue"]/div[starts-with(@id, 'color_')]

That doesn't work.

I also tried:

//div[@id="colors"]/div[starts-with(@id, 'color_')][following-sibling::div[@id="color_blue"]]

No luck with that either.

Upvotes: 1

Views: 25

Answers (1)

kjhughes
kjhughes

Reputation: 111726

This XPath,

//div[@id="colors"]/div[@id="color_blue"]/following-sibling::div

will select all div siblings following the one with @id="color_blue" within the @id="colors" div.

Upvotes: 3

Related Questions