1

I have a click event where child elements get appended to a parent element and then get removed on another click event. I want to test if those elements got removed from the parent. So is there something like

var container = element(by.css('.container'));
expect(container.length).toEqual(0);

that checks if there are any children elements?

cocoa
  • 3,806
  • 7
  • 29
  • 56

1 Answers1

4

There are special methods for checking if an element is present:

elm.isPresent();
parentElm.isElementPresent(childElm);  
browser.isElementPresent(elm);

And here are the differences between them:


Note that you can still find all elements inside a container and check the count:

var container = element(by.css('.container'));
expect(container.all(by.xpath("./*")).count()).toEqual(0);

Another alternative could be to check the inner HTML:

expect(container.getInnerHTML()).toEqual("");
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195