Jasmine StaleElementReferenceError:stale元素引用:当我单击按钮时,元素未附加到页面文档
我正在量角器中跟踪页面对象模式。在下面的代码中,我匹配用户名并单击编辑按钮Jasmine StaleElementReferenceError:stale元素引用:当我单击按钮时,元素未附加到页面文档,jasmine,protractor,Jasmine,Protractor,我正在量角器中跟踪页面对象模式。在下面的代码中,我匹配用户名并单击编辑按钮 this.clickEditButton = function (userName) { element.all(by.repeater('u in users')).each(function (elem) { elem.element(by.css('td:nth-child(1)')).getText().then(function (value) {
this.clickEditButton = function (userName) {
element.all(by.repeater('u in users')).each(function (elem) {
elem.element(by.css('td:nth-child(1)')).getText().then(function (value) {
if (value == userName) {
elem.element(by.css("a[href*='#/organisation/editUser/31']")).click();
}
});
});
};
页面已成功打开,但正在抛出“StaleElementReferenceError:stale元素引用:元素未附加到页面文档”
主要方法:
userDirectoryPage.clickEditButton('EditUser1');
userEditPage.addBasicDetails('', 'Timon', 'Thompson', 'dummy1@abc', 'abc', 'abc', 'Testing');
有人对如何解决这个问题有什么建议吗?这里的问题是您正在使用
each()
-单击编辑按钮时,DOM会发生变化,对下一个用户元素的引用会变得“过时”
您需要改为使用:
@Alecxe-解决方案通过返回元素文本对我有效。谢谢。你太棒了。
this.clickEditButton = function (userName) {
element.all(by.repeater('u in users')).filter(function (elem) {
elem.element(by.css('td:nth-child(1)')).getText().then(function (value) {
return value === userName;
});
}).first().element(by.css("a[href*='#/organisation/editUser/31']")).click();
};