Scenario 1) Stale Element Reference error
it("should have all elements", function (done) {
    var def = protractor.promise.defer();
    var prm = browser.findElements(by.css("jive")).then((elements) => {           
        elements.forEach((ele) => {
            var id = ele.getId();
            var loc = ele.getLocation();
            var inner = ele.getInnerHtml();
            var text = ele.getText();
            var tag = ele.getTagName();
        }); 
        def.then((wtf) => {
            debugger;
        });      
    });      
    done();
});
I thought that the code above would have a ton of promises on the queue after running through the iteration on all elements. But when the def.then statement runs Selenium is telling me I have Stale Elements. The iteration is running through the elements for that css.
I was hoping to get an array of resolved promises for everything the iteration requested...
Scenario 2) Gives Stale Element Reference
var promises = Array<webdriver.promise.Promise<any>>();
var allElements: webdriver.IWebElement[] = [];
it("should have all elements", function (done) {
    var alllinks: webdriver.WebElement[];
    browser.controlFlow().execute(() => {
        browser.findElements(by.tagName("a")).then((works) => {
            alllinks = works;
            alllinks.forEach((ele) => {
                promises.push(ele.getAttribute("href"));
                promises.push(ele.getId());
                promises.push(ele.getInnerHtml());
                promises.push(ele.getLocation());
            });
            //getting stale reference here...
            protractor.promise.all(promises).then((wtf) => {
                debugger;
            });
            debugger;
        });
    });
Please advise.
 
     
     
    