Hello everyone, in this blog we are going to see what is page loading strategy in selenium web driver.
What is Page Loading Strategy in Selenium?
- This page loading strategy will come into the picture whenever you are launching your browser using the
get()
method ornavigate.to()
method. - By default, Selenium WebDriver follows the standard page load strategy when it loads any page which means it waits until the entire page is loaded.
- Page Loading Strategy can be helpful in speeding up the process of web automation.
driver.get(https://www.google.com);
Whenever you launch your URL, so what will happen? This method will get hold off with your session. It will not give control to your driver until the complete page loads.
- Every browser supports the Ready State method, so selenium uses this ready state method.
- By default Selenium will wait until the Document’s Ready State is “complete.”
- The
document.readyState
property of a document describes the loading state of the current document. - By default, WebDriver will hold off on completing a navigation method (e.g.,
driver.navigate().get()
) until the document ready state is complete. - This does not necessarily mean that the page has finished loading, especially for sites like Single Page Applications that use a lot of JavaScript to dynamically load content after the Ready State returns
complete
. - Note also that this behavior does not apply to navigation that is a result of clicking an element or submitting a form.
WebDriver page load strategy supports the following values:
- Normal
- Eager
- None

Normal
- This will make Selenium WebDriver wait for the entire page to be loaded.
- When set to normal, Selenium WebDriver waits until the load event fire is returned.
- By default normal is set to the browser if none is provided.
public class pageLoadStrategy {
public static void main(String[] args) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://www.google.com");
}
}
Eager
- This will make Selenium WebDriver wait until the initial HTML document has been completely loaded and parsed, and discards the loading of stylesheets, images, and subframes.
- When set to eager, Selenium WebDriver waits until DOMContentLoaded event fire is returned.
- Finds the elements even before 100% page has been rendered.
public class pageLoadStrategy {
public static void main(String[] args) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://www.google.com");
}
}
None
- When set to none Selenium WebDriver only waits until the initial page is downloaded.
- Finds element after 100% page has loaded.
public class pageLoadStrategy {
public static void main(String[] args) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.NONE);
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://www.google.com")
}
}
Strategy | Ready States | Notes |
Normal | complete | Used by default, waits for all resources to download |
Eager | interactive | DOM access is ready, but other resources like images may still be loading |
None | any | Does not block WebDriver at all |
In addition, ChromeDriver 77.0 (which supports Chrome version 77) now supports eager as pageLoadStrategy.
Conclusion
Conclusively, when Page Loading takes too much time and you need to stop downloading additional sub-resources (images, CSS, js, etc) you can change the page load strategy through the web driver. By default, when Selenium loads a page, it follows the normal page load strategy.
Reference
https://www.selenium.dev/documentation/webdriver/capabilities/shared/