Dan*_*art 12 javascript selenium jasmine angularjs protractor
我的量角器e2e页面对象中有一个函数,它从下拉菜单中取消选中几个选项.它以前工作正常,但现在我收到以下错误:
失败:陈旧元素引用:元素未附加到页面文档
我已尝试在for循环的每次迭代中获取元素,但for循环在第一次解析promise之前执行,这意味着x的"limit"值重复传递,测试只是单击相同的下拉列表选择几次.
this.uncheckColumns = function(limit) {
element(by.className('fa-cog')).click();
element.all(by.className('multiSelectLi')).then(function(options) {
for (x = 1; x < limit; x++) {
options[x].click();
};
});
};
Run Code Online (Sandbox Code Playgroud)
ale*_*cxe 12
如何使用each(element, index)
:
element.all(by.className('multiSelectLi')).each(function(option, index) {
if (index < limit) {
option.click();
}
});
Run Code Online (Sandbox Code Playgroud)
element.all(by.className('multiSelectLi')).filter(function(option, index) {
return index < limit;
}).each(function(option) {
option.click();
});
Run Code Online (Sandbox Code Playgroud)
此外,一个解决问题的天真方法(element.all()
在循环中连续调用):
for (var index = 0; index < limit; index++) {
var option = element.all(by.className('multiSelectLi')).get(index);
option.click();
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22108 次 |
最近记录: |