I have the following code:
<div id="mydiv">
<h1>Some title</h1>
<p>don't select me</p>
<p>select me 1</p>
<p>select me 2</p>
<p>select me 3</p>
<p>don't select me</p>
</div>
I need to select p[2] through p[4].
Tried with this code and it didn’t work:
'.//*[@id="mydiv"]/p[preceding-sibling::p[4] and following-sibling::p[2]]'
You can try:
Or, your initial code can be changed to:
So that all of the
pwith preceding and followingpnodes will be selected (i.e. p[2] through p[4]).