Waiting for the page to load
In Chapter 3, Navigating through a website, we talked about navigation through a site. We covered functions such as goto
, goBack
, goForward
, and reload
. One of the options these functions have is the waitUntil
option. This option will help us determine when the function we are calling will be resolved. Let's do a quick recap. We have four options there:
domcontentloaded
, which relies on theDOMContentLoaded
event.load
: If you pass this option, thepromise
will be resolved when theload
event is fired.networkidle0
will resolve the promise when there are no more network connections for the past 500 ms.networkidle2
will resolve the promise when there are no more than 2 network connections for the past 500 ms.
Let's see how these options work with a site full of content such as https://shop.mango.com/gb. We are going to see what content is ready, depending on which waitUntil
is used: