例如使用以下html:
<div class='parent'>
<p>
<span class='child'></span>
</p>
</div>
从.child找到.parent我尝试了类似的事情:
let child = element(by.css('.child'));
let parent = child.element(by.xpath('../..')); // not working
let parent = child.element(by.xpath('ancestor::.parent')); // not working
实现这一目标的最佳途径是什么?
答案 0 :(得分:5)
您提到的定位器组合不正确。这在xpath表达式中包含了css值'.parent'。正确的方法是:
let parent = child.element(by.xpath('ancestor::div'));
OR
let parent = child.element(by.xpath('ancestor::div[1]'));