Skip to main content

waitUntil

Overview

Use the waitUntil command to wait until a specific condition is met on the page in the browser.

Usage

await browser.$(selector).waitUntil(condition, { timeout, timeoutMsg, interval });

Command Parameters

NameTypeDefaultDescription
conditionFunctionN/AThe condition to wait for.
timeoutNumber5000Timeout in milliseconds.
timeoutMsgStringN/AError message to throw when the timeout is reached.
intervalNumber500Interval in milliseconds between condition checks.

Usage Examples

example.html

<div id="someText">I am some text</div>
<script>
setTimeout(() => {
document.getElementById("someText").innerHTML = "I am now different";
}, 1000);
</script>

waitUntil.js

it("should wait until text has changed", async ({ browser }) => {
const elem = await browser.$("#someText");

await elem.waitUntil(
async function () {
return (await this.getText()) === "I am now different";
},
{
timeout: 5000,
timeoutMsg: "expected text to be different after 5s",
},
);
});

References

We'd like to give credit to the original WebdriverIO docs article, from which we drew some information while writing our version.