angularjs - Using protractor with loops -
loop index ( i ) not i'm expecting when use protractor within loop. symptoms: failed: index out of bound. trying access element @ index:'x', there 'x' elements or index static , equal last value my code for (var = 0; < max; ++i) { getpromise().then(function() { somearray[i] // 'i' takes value of 'max' }) } for example: var expected = ['expect1', 'expect2', 'expect3']; var els = element.all(by.css('selector')); (var = 0; < expected.length; ++i) { els.get(i).gettext().then(function(text) { expect(text).toequal(expected[i]); // error: `i` 3. }) } or var els = element.all(by.css('selector')); (var = 0; < 3; ++i) { els.get(i).gettext().then(function(text) { if (text === 'should click') { els.get(i).click(); // fails "failed: index out of bound. trying access element @ index:3, there 3 elements" } }) } or var els = elem