量角器通过元件的阵列点击 [英] Protractor clicking through an array of elements

查看:156
本文介绍了量角器通过元件的阵列点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是很新的端到端的测试和使用量角器/茉莉框架。我知道如何获得元素的数组以及如何点击一个锚。但如何将/是它甚至有可能通过一个元素选择器/中继器返回锚的列表?

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

任何指导/链接,以帮助将AP preciated - 谷歌搜索一直没有回注的东西对我来说,到目前为止...

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

这篇关于量角器通过元件的阵列点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆