How to wait for page to load in Selenium?

When scraping dynamic web pages with Selenium we need to wait for the page to fully load before we retrieve the page source. Using Selenium WebDriverWait function we can wait for a specific element to appear on the page which indicates that the web page has fully loaded and then grab the page source:

from selenium import webdriver
from import WebDriverWait
from import expected_conditions
from import By

driver = webdriver.Chrome()
_timeout = 10  # ⚠ don't forget to set a reasonable timeout
WebDriverWait(driver, _timeout).until(
        # we can wait by any selector type like element id:
        (By.ID, "operations-tag-Auth")
        # or by class name
        # (By.CLASS_NAME, ".price")
        # or by xpath
        # (By.XPATH, "//h1[@class='price']")
        # or by CSS selector
        # (By.CSS_SELECTOR, "h1.price")
Question tagged: Selenium, Data Parsing, Headless Browsers

Related Posts

How to Scrape Google Maps

We'll take a look at to find businesses through Google Maps search system and how to scrape their details using either Selenium, Playwright or ScrapFly's javascript rendering feature - all of that in Python.

Web Scraping with Selenium and Python Tutorial + Example Project

Introduction to web scraping dynamic javascript powered websites and web apps using Selenium browser automation library and Python.

How to Scrape Dynamic Websites Using Headless Web Browsers

Introduction to using web automation tools such as Puppeteer, Playwright, Selenium and ScrapFly to render dynamic websites for web scraping