waitForDisplayed
Wait for an element for the provided amount of milliseconds to be displayed or not displayed.
Usage
$(selector).waitForDisplayed({ 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) |
Examples
<div id="elem" style="visibility: hidden;">Hello World!</div>
<script type="text/javascript">
setTimeout(() => {
document.getElementById('elem').style.visibility = 'visible';
}, 2000);
</script>
it('should detect when element is visible', () => {
const elem = $('#elem')
elem.waitForDisplayed({ timeout: 3000 });
});
it('should detect when element is no longer visible', () => {
const elem = $('#elem')
// passing 'undefined' allows us to keep the default timeout value without overwriting it
elem.waitForDisplayed({ reverse: true });
});