# waitForExist

Wait for an element for the provided amount of milliseconds to be present within the DOM. Returns true if the selector matches at least one element that exists in the DOM, otherwise throws an error. If the reverse flag is true, the command will instead return true if the selector does not match any elements.

info

As opposed to other element commands WebdriverIO will not wait for the element to exist to execute this command.

## Usage[​](#usage "Direct link to Usage")

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

## Parameters[​](#parameters "Direct link to Parameters")

| Name                                 | Type             | Details                                                                                                  |
| ------------------------------------ | ---------------- | -------------------------------------------------------------------------------------------------------- |
| `options`<br />*optional*            | `WaitForOptions` | waitForEnabled options (optional)                                                                        |
| `options.timeout`<br />*optional*    | `Number`         | time in ms (default set based on [`waitforTimeout`](/docs/configuration.md#waitfortimeout) config value) |
| `options.reverse`<br />*optional*    | `Boolean`        | if true it waits for the opposite (default: false)                                                       |
| `options.timeoutMsg`<br />*optional* | `String`         | if exists it overrides the default error message                                                         |
| `options.interval`<br />*optional*   | `Number`         | interval between checks (default: `waitforInterval`)                                                     |

## Example[​](#example "Direct link to Example")

waitForExistSyncExample.js

```
it('should display a notification message after successful form submit', async () => {
    const form = await $('form');
    const notification = await $('.notification');
    await form.$(".send").click();
    await notification.waitForExist({ timeout: 5000 });
    expect(await notification.getText()).to.be.equal('Data transmitted successfully!')
});
it('should remove a message after successful form submit', async () => {
    const form = await $('form');
    const message = await $('.message');
    await form.$(".send").click();
    await message.waitForExist({ reverse: true });
});
```

## Returns[​](#returns "Direct link to Returns")

* **\<Boolean>** **`return`:** true if element exists (or doesn't if flag is set)
