protractor StaleElementReferenceError: Element is no longer attached to the DOM
I suspect the error is being thrown because the DOM changes between the two calls to browser.wait
. Instead of passing an elementPromise into browser.wait
, you should pass in something more indirect. You could pass the locator directly:
var waitElementToBeShown = function (elmLoc) { browser.wait(function () { return element(elmLoc).isPresent(); },10000); browser.wait(function () { return element(elmLoc).isDisplayed(); },10000);}
But you don't always have a simple locator expression. Maybe pass in a function that looks up the element? That way the lookup will re-evaluate in each wait:
var waitElementToBeShown = function (elmFunc) { browser.wait(function () { return elmFunc().isPresent(); },10000); browser.wait(function () { return elmFunc().isDisplayed(); },10000);}
Then you can call it like:
waitElementToBeShown(function() { return element(by.repeater('b in currentbookings').row(0)).element(by.cssContainingText('.tagPill', 'TestTag')));});
I'm not entirely confident in this answer, but it seems like it should work ...