我正在尝试的场景是当我在模态中有多个链接并单击每个链接时,描述会以相同的模式打开。第一次单击工作正常,但当它返回到链接列表时,它不会在for循环中单击第二个链接,并给出以下错误:
Failed: stale element reference: element is not attached to the page document
(Session info: chrome=66.0.3359.139)
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 x86_64)
我写的代码是:
this.new = function () {
element(by.xpath('')).click();
browser.sleep(5000);
browser.switchTo().defaultContent();
element.all(by.xpath('')).then(function(total){
length=total.length;
element.all(by.xpath('linkname')).then(function(ann){
for(i=0;i<length;i++)
{
ann[i].click();
browser.sleep(2000);
element(by.id("back")).click();
browser.sleep(2000);
}
});
});
};
任何建议都会受到欢迎。感谢
答案 0 :(得分:0)
browser.switchTo().defaultContent();
element.all(by.xpath('linkname')).count().then(function(count) {
for (i = 0; i < count; i++) {
(function(index) {
// find the link again after back
element.all(by.xpath('linkname')).get(index).click(); //index is the current element
browser.sleep(2000);
element(by.id("back")).click();
browser.sleep(2000);
})(i);
}
});