Jerzy Gruszka Jerzy Gruszka - 2 months ago 5x
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:


Is it doable ?


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():


where toHaveClass is a custom jasmine matcher.