angularjs - How to avoid 'Index out of Bound' exceptions with Protractor ElementArrayFinder -


i pretty new protractor , using conjunction chai , chai-as-promised. trying figure out how best handle situation, when elementarrayfinder doesn't contain elements need.

for elementfinder (no array) seems pretty simple:

element(by.css('.neverthere')).ispresent().then(function(value){     console.log('ispresent() .neverthere is: ', value, '\n'); }); 

the code above doesn't throw exception , ispresent() returns false, once promise evaluated.

once start using elementarrayfinders, gets more complicated:

var el = element.all(by.repeater(                 'property in propertypanel.properties'))         .first()         .all(by.css('.neverthere'))         .first();  el.ispresent().then(function(value){     console.log('ispresent() ', name, ' is: ', value, '\n'); }); 

the code above throws error: index out of bound. exception evaluation of ispresent(), when array, on first() evaluated, empty.

is there way access elements elementarrayfinder, - if element isn't present - elementfinder returned answers 'false' ispresent(), instead of throwing exception?

if understand correctly, can assert count of elements found 0:

var elements = element.all(by.repeater('property in propertypanel.properties')).all(by.css('.neverthere')); expect(elements.count()).tobe(0); 

using first() in conjunction browser.iselementpresent():

var elements = element.all(by.repeater('property in propertypanel.properties')).all(by.css('.neverthere')); expect(browser.iselementpresent(elements.first()).tobe(false); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -