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:
-find span text 'mybooktext'
-navigate book div
-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
Post a Comment