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").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

  1. We can get this done using the keyword waitUntil().

  2. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest