Protractor clicking through an array of elements

前端 未结 3 1024
陌清茗
陌清茗 2021-01-20 01:13

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 e

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-20 01:41

    To avoid the "staleness" problem, you have to get an array of href resolved attribute values, which map()+then() can help you with (as you've already provided). You just don't need index and you can iterate over links starting from the first:

    element.all(by.repeater('link in links')).map(function(link) {
        return link.getAttribute('href');
    }).then(function(links) {
        for (var i = 0; i < links.length; i++) {
            browser.get(links[i]);
        }
    });
    

提交回复
热议问题