iterate through elements on a page and click on them using nightwatchjs/selenium

Viewed 9076

How do I iterate through elements with a particular class name on a page and click on them? I tried using

browser.elements('css selector', element.articleItemTitle,function (links) {
        for (var i=0; i < links.value.length; i++) {
            browser.waitForElementVisible('body');
            browser.pause(1000);
            browser.elementIdClick(links.value[i].ELEMENT);
            browser.waitForElementVisible('.article-detail');
            browser.expect.element(element.postHeroTitle).to.be.present;
            browser.back();
        }
});

But it doesn't always click on a specified element each time it iterates through the loop.

I get the error: stale element reference: element is not attached to the page document

using nightwatch

2 Answers
Related