Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor Check if Element Does Not Exist

I have a setting in my angular based website that turns a dropdown on and off. If it is off, then it does not show on the main page.

With Protractor, I need to check to see if this element is not present when the switch is off. However, I should not be thrown into Element Not Found Error, as it is one test in a set of many. How should I do this?

I have tried to do:

expect($$('.switch').count()).to.equal(0).and.notify(next); 

But I am getting an AssertionError with this...

like image 440
Sakamoto Kazuma Avatar asked Aug 14 '14 17:08

Sakamoto Kazuma


People also ask

Is element present in protractor?

In protractor, there are, basically, 3 ways to check if an element is present: var elm = element(by.id("myid")); browser. isElementPresent(elm);


1 Answers

Another option that worked a bit better for me, and uses protractor 'way' of doing things http://angular.github.io/protractor/#/api?view=ElementArrayFinder.prototype.all

element.all(by.css('.k-loading-image')).then(function(items) {     expect(items.length).toBe(0); }); 

(I wanted to check that a loading indicator had disappeared)

like image 80
Carl Avatar answered Oct 02 '22 15:10

Carl