Webdriverio Wait for Page to Load
Is There a Way to Make Webdriverio Wait for a Page to Load? I Saw That in Java I Can Have Something Like: executeScript("return Document. readyState")...
Is there a way to make webdriverio wait for a page to load? I saw that in java I can have something like:
executeScript("return document.readyState").equals("complete"));
or
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
Is there a way I can do it in webdriverio? I know that I can use waits to wait for a specific element but I am looking for a way to wait for the whole page the load
3 Answers
We can get this done using the keyword waitUntil().
For details about document.readyState property, refer here()
Code:
browser.waitUntil(function () {
const state = browser.execute(function () {
return document.readyState;
});
//console.log("state:" + state)
return state === 'complete';
},
{
timeout: 60000, //60secs
timeoutMsg: 'Oops! Check your internet connection'
});
simplified version of @ Sadeesh code:
browser.waitUntil(
() => browser.execute(() => document.readyState === 'complete'),
{
timeout: 60 * 1000, // 60 seconds
timeoutMsg: 'Message on failure'
}
);
You can add browser.setTimeout({ 'pageLoad': 10000 }) to your wdio.conf.js file within the before: function
see for further detail.