xpath - trying to get all p tag text between two h2 tags -


<h2><span>title1</span></h2> <p>text want</p> <p>text want</p> <p>text want</p> <p>text want</p> <h2>second title want stop collecting p tags after</h2> 

i can p tags identifying text within h2, preceeding-sibling::p grabs p tags end of dom. have tried use "and" selector declare start , end returns null. must missing here i've been stuck on quite while. cannot predict how many p tags need index number on p element not going me in case.

here xpath used of following p tags after h2. problem grabs p tags end of dom.

//span[contains(text(), "title1")]/ancestor::h2/following-sibling::p 

so want p tags between 2 specific h2 tags. xpath query sounds.

//p[    preceding-sibling::h2[span='title1'] ,    following-sibling::h2[.='second title want stop collecting p tags after'] ] 

the query simplified selecting p first preceding h2 element starting element. in other words, there no other h2 previous siblings between current p , header.

//p[preceding-sibling::h2[1][span='title1']] 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -