Protractor by clicking on an array of items

I am new to testing e2e and using the protractor / jasmine structure. I know how to get an array of elements, as well as how to click on an anchor. But how could / even click on the list of anchors returned by the element selector / repeater?

I try in many ways, but as an example (the last one that was not removed by 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 ');

        });
    });
});

It seems that the first element and click, but come to the next iteration that it hangs (I can understand why, but I am struggling to figure out a way to solve the problem - is this some kind of promise and decisive factor that I need to take the bill?)

Return error

Failure: link to deprecated element: element not attached to page document

/ - googling ...

!

+4
3

, . , - , :)

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

"", href, map() + then() ( ). index, , :

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]);
    }
});
0

01

public findSpecificElementAndClick(element: ElementArrayFinder,expected: number){
        let clickedIndex: number = -1;
        element.filter(function (elementItem, index) {
            clickedIndex++;
            if(index === (expected-1)){
                element.get(clickedIndex).click();
                return true;
            }
        }).then(function (bool) {

        }).catch(function (err) {
            throw new FrameworkException('Ooops ! Error... '+err.message);
        });
    }

02
public findTextAndClick(element: ElementArrayFinder,expected: string) {
        let clickedIndex: number = -1;
        let status :boolean = false;
        element.filter(function (elementItem, index) {
            return elementItem.getText().then(function (text) {
                if(text === expected) {
                    clickedIndex = index;
                    status = true;
                    return true;
                }
            });
        }).then(function (bool) {
            if(!status){
                throw new ApplicationException("Ooops ! Couldn't found "+expected+" Record ...");
            }else{
                element.get(clickedIndex).click();
            }
        }).catch(function (err) {
            throw new FrameworkException('Ooops ! Error... '+err.message);
        });
    }
0

Source: https://habr.com/ru/post/1584256/


All Articles