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.
Usage
$(selector).waitForExist({ timeout, reverse, timeoutMsg, interval })
Parameters
| Name | Type | Details |
|---|---|---|
optionsoptional | WaitForOptions | waitForEnabled options (optional) |
options.timeoutoptional | Number | time in ms (default: 500) |
options.reverseoptional | Boolean | if true it waits for the opposite (default: false) |
options.timeoutMsgoptional | String | if exists it overrides the default error message |
options.intervaloptional | Number | interval between checks (default: waitforInterval) |
Example
it('should display a notification message after successful form submit', function () {
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', function () {
const form = $('form');
const message = $('.message');
form.$(".send").click();
// passing 'undefined' allows us to keep the default timeout value without overwriting it
message.waitForExist({ reverse: true });
});