html - XPath searching multiple nested elements -


i have following html document

<div class="books">   <div class="book">     <div>       there many deep nested elements here, somewhere there 1 span  text e.g. 'mybooktext' within these       <div>         <div>           <div>             <span>mybooktext</span>           </div>        </div>      </div>   </div> <div>  there many nested elements here, somewhere there link class called 'mylinkclass' within these. (this element want find)  <div>    <div>      <a class="mylinkclass">bla</a>    </div>  </div> </div> </div> <div class="book"> <div>  there many deep nested elements here, somewhere there 1 span     text e.g. 'mybooktext' within these    <div>      <span>mybooktext</span>    </div>  <div> </div> <div>  there many nested elements here, somewhere there link class called 'mylinkclass' within these. (this element want find)  <div>    <a class="mylinkclass">bla</a>  </div> </div> </div> <div class="book"> same above </div> </div> 

i want find link element (link has class called 'mylinkclass') within book element, based on text of span within same book element.

so like:

  1. -find span text 'mybooktext'

  2. -navigate book div

  3. -find link class 'mylinkclass' within book div

this should done using 1 xpath statement

in few looking for:

" //span[contains(text(),'mybooktext')]             /ancestor::div[@class='book']             //a[@class='mylinkclass']"  

//span[contains(text(),'mybooktext')] find san containing "mybooktext"
/ancestor::div[@class='book'] navigate book div (in deeps)
//a[@class='mylinkclass'] find link class 'mylinkclass' within book div (in deeps)

update: change first condition to
//span[(text() ='mybooktext'] if mybooktext text in span


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -