Jerzy Gruszka Jerzy Gruszka - 1 year ago 76
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 ?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download