import Admonition from "@theme/Admonition";
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.
await browser.$(selector).waitForExist({ timeout, reverse, timeoutMsg, interval });| **Name** | **Type** | **Default** | **Description** |
| timeout | Number | 500 | Timeout in milliseconds. |
| reverse | Boolean | false | If _true_, the command will wait for the opposite condition: the element does not exist. |
| timeoutMsg | String | _N/A_ | Error message to throw when the timeout is reached. |
| interval | Number | [waitforInterval][wait-for-interval] | Interval in milliseconds between condition checks. |
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 });
});We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.