html - Cannot find correct element with same class name -
i have following html snippet:
<div id="result-1"> <div class="page"> <div class="collapsingblock"> <h4>click me</h4> </div> <div class="collapsingblock collapsed"> <h4>no, click me</h4> </div> </div> </div> what i'm trying do, find second collapsingblock , it's h4
i have following:
(//div[@id="result-1"]/div[@class="page"]/div[@class="collapsingblock"])[2]/h4
my xpath doesn't return element. if replace [1] finds first instance of collapsingblock though
any ideas?
thanks
update:
i have noticed, html using javascript add/remove additional class second collapsingblock, collapsed
the problem value of class attribute of second inner div element not equal "collapsingblock", can see:
<div class="collapsingblock collapsed"> <h4>no, click me</h4> </div> even though class has clear-cut semantics in html, not mean special xpath, it's attribute other.
use contains() avoid problem:
(//div[@id="result-1"]/div[@class="page"]/div[contains(@class,"collapsingblock")])[2]/h4 then, result of expression above is
<h4>no, click me</h4> by way, parentheses around lefthand part of expression not necessary in case:
//div[@id="result-1"]/div[@class="page"]/div[contains(@class,"collapsingblock")][2]/h4 will same, given particular input document.
Comments
Post a Comment