isExisting
Overview
Use the isExisting
command to determine whether a given DOM element exists.
The command returns true
if the selected element exists, 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).isExisting();
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>
isExisting.js
it("should detect if elements are existing", async ({ browser }) => {
let elem = await browser.$("#someRandomNonExistingElement");
let isExisting = await elem.isExisting();
console.log(isExisting); // outputs: false
elem = await browser.$("#notDisplayed");
isExisting = await elem.isExisting();
console.log(isExisting); // outputs: true
elem = await browser.$("#notVisible");
isExisting = await elem.isExisting();
console.log(isExisting); // outputs: true
elem = await browser.$("#notInViewport");
isExisting = await elem.isExisting();
console.log(isExisting); // outputs: true
elem = await browser.$("#zeroOpacity");
isExisting = await elem.isExisting();
console.log(isExisting); // 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.