The scenario I am trying is when I have multiple links in the modal and clicking on each link a description opens up in the same modal. The first click works fine, but when it goes back to the list of links, it doesn't click on the second link in a for loop, and gives the following error:
Failed: stale element reference: element is not attached to the page document
(Session info: chrome=66.0.3359.139)
(Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 x86_64)
The code I have written is:
this.new = function () {
element(by.xpath('')).click();
browser.sleep(5000);
browser.switchTo().defaultContent();
element.all(by.xpath('')).then(function(total){
length=total.length;
element.all(by.xpath('linkname')).then(function(ann){
for(i=0;i<length;i++)
{
ann[i].click();
browser.sleep(2000);
element(by.id("back")).click();
browser.sleep(2000);
}
});
});
};
Any advice would be welcomed. Thanks