我需要编写一个测试来检查 div 的父级是否具有特定类,在本例中为“父级”。
我有这个代码:
....
<div class="parent">
<div id="child"></div>
</div>
....
我尝试过的:
element(by.id('child')).getWebElement().getDriver().getAttribute('class');
但是我收到以下错误并且不知道如何继续..
.getWebElement(...).getDriver(...).getText is not a function
最佳答案
您没有正确获取父项。使用 xpath 最简单:
element(by.id('child')).element(by.xpath('..')).getAttribute('class');
在此示例中,by.xpath('..')
应选择父元素。
关于angularjs - 如何从 Protractor 中的元素获取父级中的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47409077/