Home stale element references in loop after redirection to another page
 i am trying to choose a certain element of similar objects on a website, in my e2e tests, and to click it then to change to another site, related to that element. The Problem is that the loop is still going on after the page is changed because the promise resolves asynchronous (i'm new to all this stuff) Here the code:  goToCartridge(name){ let done = false; element(by.id('dashboard')).all(by.className('card z-depth-1')).then( elems => { for(let i = 0; i < elems.length ; i++ ){ if(done) break; elems[i].element(by.tagName('h2')).getText().then( text => { if(name === text) { element(by.id('cartridge-' + i)).click(); done = true; } return; }); } }); }  How can i wait for the async part inside the loop before the next iteration starts? i searched alot for a solution, but couldnt find one yet.