How do I make Selenium wait for a page to load?
Selenium has three mechanisms for handling page loads. Set a pageLoadStrategy (normal, eager, or none) on the driver to control what counts as “loaded” during navigation, use an explicit WebDriverWait to block until a specific element or DOM condition is true, and reach for set_page_load_timeout only to cap how long a hung navigation can stall the test. Explicit waits are the right default for almost everything.
Wait types compared
There are four knobs you actually use. Pick one based on what you are waiting for, not on which one you remember the name of.
| Approach | What it waits for | When to use |
|---|---|---|
Explicit wait (WebDriverWait + expected_conditions) | A specific condition on a specific element or the DOM | Default. Use this for almost every “wait until X” case. |
pageLoadStrategy driver option | Navigation completion, per document.readyState | Set once on the driver to skip image loading (eager) or to stop blocking on driver.get (none). |
set_page_load_timeout(n) | Hard cap on driver.get and other navigation calls | Bail out of hung navigations. Default is 300 seconds. |
Implicit wait (driver.implicitly_wait) | Any find_element lookup, globally | Avoid. Do not mix with explicit waits, the polling interactions are unpredictable. |
time.sleep is not on the list. Use it only as a temporary debugging aid, never in committed test code.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver.set_page_load_timeout(30) # cap on driver.get itself
driver.get("https://example.com/dashboard")
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "[data-testid='loaded']"))
)Swap presence_of_element_located for visibility_of_element_located if the element is in the DOM before it is rendered, or element_to_be_clickable if you are about to click it.
Setting page load strategy
pageLoadStrategy controls what driver.get blocks on. normal waits for document.readyState == "complete" (the default and what most people want). eager returns at interactive, which is DOMContentLoaded with images and subresources still loading. none returns the moment the navigation is dispatched, leaving you to decide when the page is ready via an explicit wait.
from selenium import webdriver
opts = webdriver.ChromeOptions()
opts.page_load_strategy = "eager"
driver = webdriver.Chrome(options=opts)Use eager to shave seconds off image-heavy pages. Use none when the page does its real work after load fires (SPAs, infinite scroll) and you only want explicit waits to gate progress.
Related articles
All articles →How to Scroll Page using Selenium in Python
Explore various techniques for scrolling pages using Selenium in Python. Learn about JavaScript Executor, Action Class, keyboard events, handling overflow elements, and tips for improving scrolling accuracy, managing pop-ups, and dealing with frames and nested elements.
Web Scraping with XPath in Selenium
Using XPath in Selenium for scraping helps to parse dynamic elements and to find element at any level of DOM structure.
The Complete Guide to Web Scraping with Selenium in Python
Learn how to use Selenium for web scraping in Python. Automate browser actions, handle dynamic pages, and extract structured data.
Move Selenium off your own servers
HasData renders pages, rotates proxies, and retries blocked fetches through an API.