iterate through elements on a page and click on them using nightwatchjs/selenium
<p>How do I iterate through elements with a particular class name on a page and click on them? I tried using </p>

<pre><code>browser.elements('css selector', element.articleItemTitle,function (links) {
        for (var i=0; i &lt; 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();
        }
});
</code></pre>

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

<p>I get the error: <code>stale element reference: element is not attached to the page document</code></p>

<p>using nightwatch</p>