isDisplayed
Overview
Use the isDisplayed
command to determine whether a given DOM element is displayed.
The command returns true
if the selected DOM element is displayed; otherwise, it returns false
.
warning
Unlike other element commands, Testplane will not wait for the element to exist before executing this command.
Usage
await browser.$(selector).isDisplayed();
Usage Examples
index.html
<div id="notDisplayed" style="display: none"></div>
<div id="notVisible" style="visibility: hidden"></div>
<div id="notInViewport" style="position:absolute; left: 9999999"></div>
<div id="zeroOpacity" style="opacity: 0"></div>
isDisplayed.js
it("should detect if an element is displayed", async ({ browser }) => {
let elem = await browser.$("#notDisplayed");
let isDisplayed = await elem.isDisplayed();
console.log(isDisplayed); // outputs: false
elem = await browser.$("#notVisible");
isDisplayed = await elem.isDisplayed();
console.log(isDisplayed); // outputs: false
elem = await browser.$("#notExisting");
isDisplayed = await elem.isDisplayed();
console.log(isDisplayed); // outputs: false
elem = await browser.$("#notInViewport");
isDisplayed = await elem.isDisplayed();
console.log(isDisplayed); // outputs: true
elem = await browser.$("#zeroOpacity");
isDisplayed = await elem.isDisplayed();
console.log(isDisplayed); // outputs: true
});
References
We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.