Here is the code:
<li class="abc">
<div class="abc">
<input type="checkbox">
</div>
<div class="xyz">
<div class="headline">Mongo like candy</div>
<div>
</li>
<li class="abc">
<div class="abc">
<input type="checkbox">
</div>
<div class="xyz">
<div class="headline">Candygram for mongo</div>
<div>
</li>
Xpath challenge. I want locate the checkbox of the li which contains the headline “Mongo like candy” so I can select it using Selenium. In other words, how do you locate the checkbox from here:
li//div[@class='abc']//input[@type='checkbox']
but qualifying it with a different attribute within the same parent node:
li//div[@headline][contains(text(),"Mongo like candy")]
The basic idea is to qualify the final path with a predicate, i.e.
The predicate expresses the condition on the li that you want:
Putting them together yields: