Jerzy Gruszka Jerzy Gruszka - 3 months ago 7
CSS Question

Add a locator at the same level to the variable

My goal is to find an element with id and class both. I do it like this:

return element(by.css('#right.closed')).isPresent();


That is working fine. But I want to improve and introduce a variable for:

public static rightPanel = element(by.css('#right'));


I want to use the rightPanel and on the fly with use of that variable add another condition at the same level:

rightPanel.addConditionClassMustBeClosedAtThatElement.isPresent();


Is it doable ?

Answer

The addConditionClassMustBeClosedAtThatElement can be implemented via getAttribute():

rightPanel.isPresent().then(function (isPresent) {
    rightPanel.getAttribute("class").then(function (classes) {
        console.log(isPresent && classes.indexOf("closed") >= 0);
    });
});

Or, if were to add expectations via expect():

expect(rightPanel.isPresent()).toBe(true);
expect(rightPanel).toHaveClass("closed");

where toHaveClass is a custom jasmine matcher.

Comments