【发布时间】:2019-03-25 14:28:09
【问题描述】:
我在其中一个量角器页面中创建了一个函数。单击该功能后,我将转到另一个我使用了 require 关键字的页面。
this.naviagteToSwaggerOrReadme = function(str) {
this.endpointDropdown.click();
browser.sleep(2000);
//element(by.partialLinkText('swagger/index.html')).click();
element(
by.className('popover ng-scope ng-isolate-scope bottom fade in')
)
.all(by.tagName('a')).then(function(obj) {
console.log('Number of elements with the a tag in the parent element is ' + obj.length);
for (let i = 0; i < obj.length; i++) {
obj[i].getText().then(function(text) {
console.log('The text on the link is ' + text);
var linkText = text;
if (linkText.toLowerCase().indexOf(str) !== -1) {
obj[i].click();
} else {
obj[i + 1].click();
}
})
}
});
browser.sleep(5000);
return require('./Swagger.js');
};
我正在调用相同的函数。
swagger = appsPageOne.naviagteToSwaggerOrReadme('swagger');
swagger.getSwaggerTitle().then(function(title){
console.log('This is the title '+title);
})
但我得到的错误是:
Message:
Failed: stale element reference: element is not attached to the page document
(Session info: chrome=74.0.3729.6)
(Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.15063 x86_64)
Stack:
StaleElementReferenceError: stale element reference: element is not attached to the page document
【问题讨论】:
-
obj[i].click();in for 循环导致当前页面更改,下一个obj.click()在找到它的页面上不起作用。所以举报StaleElementReferenceError -
有什么方法可以突破并返回下一页..我在循环中使用了 break..return 但没有运气
-
是只点击第一个匹配的
<a>还是一个一个点击所有匹配的<a>?
标签: javascript protractor