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
$(selector).waitForExist({ timeout, reverse, timeoutMsg, interval })
Parameters
Name | Type | Details |
---|---|---|
options optional | WaitForOptions | waitForEnabled options (optional) |
options.timeout optional | Number | time in ms (default: 500) |
options.reverse optional | Boolean | if true it waits for the opposite (default: false) |
options.timeoutMsg optional | String | if exists it overrides the default error message |
options.interval optional | Number | interval between checks (default: waitforInterval ) |
Example
- Asynchronous Mode
- Synchronous Mode
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 });
});
waitForExistSyncExample.js
it('should display a notification message after successful form submit', () => {
const form = $('form');
const notification = $('.notification');
form.$(".send").click();
notification.waitForExist({ timeout: 5000 });
expect(notification.getText()).to.be.equal('Data transmitted successfully!')
});
it('should remove a message after successful form submit', () => {
const form = $('form');
const message = $('.message');
form.$(".send").click();
message.waitForExist({ reverse: true });
});
caution
Synchronous Mode will depcrecated with Node.js v16. With an update to the underlying Chromium version it became technically impossible to provide the same synchronous behavior. We recommend to start transition to asynchronous command execution. For more information, see our RFC.