量角器单击元素数组

Protractor clicking through an array of elements(量角器单击元素数组)

本文介绍了量角器单击元素数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 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.
    };
});

这篇关于量角器单击元素数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:量角器单击元素数组

基础教程推荐