I am writing Protractor automation tests and have encountered a problem. The wait command does not actually wait for one of the elements in the array. See the example below: I'm trying to wait for the first element after going to a web page.
var category = element.all(by.repeater('category in listCtrl.categories')); var category2 = $$('.category-name.custom-tooltip-link.ng-binding'); var EC = protractor.ExpectedConditions; describe('wait for the first category', function() { it('wait', function() { browser.get('http://www.deep.mg/'); browser.wait(EC.visibilityOf(category.get(0)), 20000); browser.wait(EC.visibilityOf(category2.get(0)), 20000); }); });
But the test fails with the following error: Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator by.repeater("category in listCtrl.categories") Failed: Index out of bound. Trying to access element at index: 0, but there are only 0 elements that match locator by.repeater("category in listCtrl.categories") .
The error does not depend on the type of locator, because it appears for both: "by.repeater" and "by.css". The selectors are fine, test passes after adding the "sleep" command:
var category = element.all(by.repeater('category in listCtrl.categories')); var category2 = $$('.category-name.custom-tooltip-link.ng-binding'); var EC = protractor.ExpectedConditions; describe('wait for the first category', function() { it('wait', function() { browser.get('http://www.deep.mg/'); browser.sleep(15000); browser.wait(EC.visibilityOf(category.get(0)), 20000); browser.wait(EC.visibilityOf(category2.get(0)), 20000); category.count().then(function(count1) { console.log(count1);
Also, the timeout parameter does not help, it just ignores it and does not work immediately.
So the question is, how to wait for a specific element of an array? Am I missing something? Thanks.
source share