問題描述
我對 e2e 測試和使用量角器/jasmine 框架非常陌生.我知道如何獲取元素數組以及如何單擊錨點.但是如何/甚至可能點擊元素選擇器/中繼器返回的錨點列表?
I'm quite new to e2e testing and in using protractor / jasmine framework. I know how to get an array of elements and also how to click on an anchor. But how would / is it even possible to click through a list of anchors returned by a element selector / repeater?
我一直在嘗試各種方法,但作為一個例子(最新的一個還沒有被刪除,哈哈),這就是我得到的:
I've been trying various ways, but as an example (latest one which hasn't been deleted lol) this is what I got:
element.all(by.repeater('link in links')).then(function(links) {
links.forEach(function(link) {
link.click().then(function() {
console.log('callback for click ');
});
});
});
這似乎采用了第一個元素并點擊通過,但是下一次迭代它掛起(我明白為什么,但努力想辦法解決 - 這是我需要采取的某種承諾和解決因素嗎?考慮?)
This appears to take the first element and click through, however come the next iteration it hangs (I can see why, but struggling to figure a way to resolve - is this some kind of promise & resolve factor i need to take into account?)
返回的錯誤是
失敗:過時的元素引用:元素未附加到頁面文檔
Failed: stale element reference: element is not attached to the page document
任何指導/幫助鏈接將不勝感激 - 到目前為止,谷歌搜索尚未向我返回任何值得注意的信息...
Any guidance / link to help would be appreciated - googling hasn't returned anything of note to me so far...
提前致謝!
推薦答案
設法找到解決方法,盡管感覺不太對.無論如何,如果有人有更好的建議,請隨時發布:)
Managed to figure a workaround, although this doesn't feel quite right. Anyway, if anyone has better suggestion feel free to post :)
element.all(by.repeater('link in links')).map(
function(link, index) {
return {
index: index,
href: link.getAttribute('href')
};
})
.then(function(links) {
for (var i = links.length - 1; i >= 0; i--) {
browser.get(links[i].href);
// do some page specific stuff here.
};
});
這篇關于量角器單擊元素數組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!