当我添加一个具有某些值的新按钮时,它会动态添加到 DOM 中。此按钮的非 Angular HTML 元素是:
<li class="ui-state-default droppable ui-sortable-handle" id="element_98" data-value="2519">
25.19 EUR
<button type="button" class="btn btn-default removeParent">
<span class="glyphicon glyphicon-remove" aria-hidden="true">
</span>
</button>
</li>
删除此按钮后,我想检查它是否不再存在。我正在搜索的元素是 data-value="2519"
这可以是我设置的任何元素,例如 2000、1000、500、1050,...
在页面对象文件中,我尝试使用以下内容:
this.newValueButtonIsNotPresent = function(item) {
newValueButton = browser.element(by.id("containerQUICK_ADD_POINTS")).all(by.css('[data-value="' + item + '"]'));
return newValueButton.not.isPresent();
};
在规范文件中,我按如下方式调用此函数:
var twentyEurosButtonAttributeValue = '2000';
describe("....
it ("...
expect(predefined.newValueButtonIsNotPresent(twentyEurosButtonAttributeValue)).toBeTruthy();
我知道这是不正确的,但是我如何才能实现类似的目标或者还有其他方法吗?
最佳答案
愚蠢的我,我找到了一个简单的解决方案。相反,我动态定位一个元素,找到列表中的第一个元素,该元素始终是新添加的元素,然后检查其文本是否不匹配:
页面对象文件:
this.newValueButtonIsNotPresent = function() {
newValueButton = browser.element(by.id("containerQUICK_ADD_POINTS")).all(by.tagName('li')).first();
return newValueButton.getText();
};
规范文件:
// verify element 20.00 EUR is not present
predefined.newValueButtonIsNotPresent().then(function(value) {
expect(value).not.toEqual(twentyEurosText);
});
关于javascript - Protractor 中的动态属性值元素定位器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42385111/