Search on descendants of an element

The advantage of separating the child from the child css selector would only be if you’d like to use the parent for something else. Otherwise, it’s slightly faster to do it in one call, like expect(element('#parent_1 > .red')).toBe('red'); since Protractor doesn’t need to make two calls to the browser in this case.

Another reason to use the first approach would be if you were using a Locator strategy that cannot be expressed in CSS. For example:

var parent = element(by.css('.foo'));
var child = parent.element(by.binding('childBinding'));
expect(child.getText()).toEqual('whatever');

Leave a Comment