Check if element is not displayed - WebDriverJS Check if element is not displayed - WebDriverJS selenium selenium

Check if element is not displayed - WebDriverJS


isDisplayed() works well when used on a single element. Is there a similar way to check if multiple elements are displayed?

This can be solved by using map(). Example:

element.all(by.css(".element")).map(function (elm) {    return elm.isDisplayed();});

This would return a promise resolving into an array of booleans.

If you want a single boolean value, you can use reduce():

element.all(by.css(".element")).reduce(function (acc, elm) {    return elm.isDisplayed().then(function (isDisplayed) {        return isDisplayed && acc;    });}, false);


To answer your questions -

  • No, there is no function which returns true if element is absent. You can check for negative(false) condition on the existing isDisplayed() method. You can use various test frameworks with webdriverjs and perform the false assertions like jasmine, mocha, etc... How to use webdriverjs with Mocha and testing with jasmine
  • If you want to check if multiple elements are displayed then you can either use inbuilt loops like .each() or .map() or .reduce()(applicable only if you have multiple elements that you can get using a single locator) or you have to check them individually.

Hope this helps.


I show how I solved the issue, using jasmine, in case that someone may need it in the future:

driver.findElement(webdriver.By.css('.element')).isDisplayed()    .then(function(displayed) {        expect(displayed).not.toBe(true);    });