Let's say I have this HTML
<div class="item-wrapper">
<div>
<h6>My Header 1</h6>
<div>
<div>
<div>
<label>
<input type="checkbox" />
<span class="class1">Text 2</span>
<span class="class2"></span>
</label>
<div>
</div>
</div>
<div class="item-wrapper">
<div>
<h6>My Header 2</h6>
<div>
<div>
<div>
<label>
<input type="checkbox" />
<span class="class1">Text 2</span>
<span class="class2"></span>
</label>
<div>
</div>
</div>
How do I get to any child to the common parent, i.e. <div class="item-wrapper">
? In this case, the attribute is the class. However, the attribute could be anything that can identify the common ancestor.
var xPathToAncestor = "ancestor::div[@class='item-wrapper']";
var ancestor = child.FindElement(By.XPath(xPathToAncestor)
I've tried so many combinations //ancestor::div[@class='item-wrapper']
, .//ancestor::div[@class='item-wrapper']
, but nothing is working.