Skip to main content

waitForDisplayed

Overview

Use the waitForDisplayed command to wait until an element becomes displayed or not displayed within a specified number of milliseconds.

warning

Unlike other element commands, Testplane will not wait for the element to exist before executing this command.

Usage

await browser.$(selector).waitForDisplayed({ timeout, reverse, timeoutMsg, interval });

Command Parameters

NameTypeDefaultDescription
timeoutNumber500Timeout in milliseconds.
reverseBooleanfalseIf true, the command will wait for the opposite condition: the element becomes not displayed.
timeoutMsgStringN/AError message to throw when the timeout is reached.
intervalNumberwaitforIntervalInterval in milliseconds between condition checks.

Usage Examples

index.html

<div id="elem" style="visibility: hidden;">Hello World!</div>
<script type="text/javascript">
setTimeout(() => {
document.getElementById("elem").style.visibility = "visible";
}, 2000);
</script>

waitForDisplayed.js

it("should detect when element is visible", async ({ browser }) => {
const elem = await browser.$("#elem");
await elem.waitForDisplayed({ timeout: 3000 });
});

it("should detect when element is no longer visible", async ({ browser }) => {
const elem = await browser.$("#elem");
await elem.waitForDisplayed({ reverse: true });
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.