Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 2.17 KB

File metadata and controls

58 lines (40 loc) · 2.17 KB

import Admonition from "@theme/Admonition";

waitForExist

Overview {#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.

Usage {#usage}

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

Command Parameters {#parameters}

**Name****Type****Default****Description**
timeoutNumber500Timeout in milliseconds.
reverseBooleanfalseIf _true_, the command will wait for the opposite condition: the element does not exist.
timeoutMsgString_N/A_Error message to throw when the timeout is reached.
intervalNumber[waitforInterval][wait-for-interval]Interval in milliseconds between condition checks.

Usage Examples {#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.