Skip to main content

waitForExist

Overview

Use the waitForExist command to wait until an element appears in the DOM within a specified number of milliseconds.

The command returns true if the selector matches at least one element existing in the DOM; otherwise, it throws an error. If the reverse parameter is set to true, the command reverses its logic and returns true if the selector matches no elements.

warning

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

Usage

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

Command Parameters

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

Usage Examples

it("should display a notification message after successful form submit", async ({ browser }) => {
const form = await browser.$("form");
const notification = await browser.$(".notification");

await form.$(".send").click();
await notification.waitForExist({ timeout: 5000 });

assert.equal(await notification.getText(), "Data transmitted successfully!");
});

it("should remove a message after successful form submit", async ({ browser }) => {
const form = await browser.$("form");
const message = await browser.$(".message");

await form.$(".send").click();
await message.waitForExist({ 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.