# Playwright: Wait for Page to Load in Python

> Playwright wait for page to load, in Python: why load and networkidle returned with 0 items, and wait_for_selector, expect and wait_for_response, timed.

[Home](https://quanticdata.io/) / [Blog](https://quanticdata.io/blog/) / Playwright: Wait for Page to Load in Python

# Playwright wait for page to load in Python: every wait timed on a slow page

Guides · Nov 20, 2026 · 5 min read · By [Aldo Morese](https://quanticdata.io/about/), founder of QuanticData

![Playwright waits timed in Python on a page that adds its quotes after a delay: goto with commit, domcontentloaded, load and networkidle all returned within 1.67 seconds with 0 quotes on the page, while wait_for_selector returned after 11.24 seconds with all 10; the card recommends waiting for the element, the response or the URL.](https://quanticdata.io/blog/playwright-wait-for-page-load/hero.webp?v=20261120h)

On this page

- [What goto() waits for, and why it was not enough](https://quanticdata.io/blog/playwright-wait-for-page-load/#what-goto-waits-for-and-why-it-was-not-enough)
- [Wait for the element](https://quanticdata.io/blog/playwright-wait-for-page-load/#wait-for-the-element)
- [Wait for the data itself: expect_response](https://quanticdata.io/blog/playwright-wait-for-page-load/#wait-for-the-data-itself-expect-response)
- [Wait after a click: wait_for_url](https://quanticdata.io/blog/playwright-wait-for-page-load/#wait-after-a-click-wait-for-url)
- [Why not just sleep?](https://quanticdata.io/blog/playwright-wait-for-page-load/#why-not-just-sleep)
- [Which wait for which job](https://quanticdata.io/blog/playwright-wait-for-page-load/#which-wait-for-which-job)
- [Timeouts](https://quanticdata.io/blog/playwright-wait-for-page-load/#timeouts)
- [Waiting through a proxy](https://quanticdata.io/blog/playwright-wait-for-page-load/#waiting-through-a-proxy)

In Playwright, `page.goto()` already waits for the page's load event. To wait for the content you need, wait for that content: `page.wait_for_selector("css")` or `expect(locator).to_be_visible()` for an element, `page.expect_response()` for an API call, `page.wait_for_url()` after a click. `networkidle` and fixed sleeps are unreliable.

**Run it on the free credit.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-lead&utm_content=playwright-wait-for-page-load) · [Explore Web Scraping API](https://quanticdata.io/web-scraping-api/)

We timed every option on 20 November 2026 with Python 3.12.10, Playwright 1.64.1 and Chromium 156, through a QuanticData Residential Premium session in the US, on quotes.toscrape.com/js-delayed/, a public practice page that adds its quotes after a delay, like many real sites that load data after the first paint.

## What goto() waits for, and why it was not enough

```
for wu in ("commit", "domcontentloaded", "load", "networkidle"):
    page.goto("https://quotes.toscrape.com/js-delayed/", wait_until=wu)
    print(wu, page.locator("div.quote").count())
```

| `wait_until` | Returns when | Our time | Quotes on the page |
| --- | --- | --- | --- |
| commit | The response starts arriving | 1.11 s | 0 |
| domcontentloaded | The HTML is parsed | 1.36 s | 0 |
| load (default) | The page and its resources are loaded | 1.38 s | 0 |
| networkidle | No network activity for a short while | 1.67 s | 0 |

All four returned with nothing to scrape. The page waits on a timer before adding its quotes, so the network goes quiet first and the content comes later. Playwright's own documentation marks networkidle as discouraged and recommends waiting on the elements you need instead, which is what the next sections do.

## Wait for the element

```
page.goto(URL, wait_until="domcontentloaded")
page.wait_for_selector("div.quote")                    # 11.24 s, then 10 quotes

from playwright.sync_api import expect
expect(page.locator("div.quote").first).to_be_visible(timeout=30000)   # 10.76 s

page.locator("div.quote").first.wait_for(state="visible")              # 10.01 s
```

All three returned once the quotes existed, and all 10 were there. Combine them with `wait_until="domcontentloaded"`: there is no reason to also wait for images and fonts when the element is what you need. The element waits measured the real delay of the page, about ten seconds, instead of a guess, so they also tell you how slow a site is.

When one element is not enough, wait for a condition in the page: `page.wait_for_function("document.querySelectorAll('div.quote').length >= 10")` returned in 10.03 s with the full list.

## Wait for the data itself: expect_response

Often the content comes from a JSON call. Waiting for that response gives you the data without parsing the page at all. On the infinite-scroll page of the same site:

```
page.goto("https://quotes.toscrape.com/scroll", wait_until="domcontentloaded")
with page.expect_response(lambda r: "/api/quotes" in r.url and r.status == 200) as info:
    page.mouse.wheel(0, 20000)
data = info.value.json()
print(info.value.url, data["page"], len(data["quotes"]))
# https://quotes.toscrape.com/api/quotes?page=1  1  10
```

Start the `with` block before the action that triggers the request, as above, or you can miss a fast response. More on finding these calls in [scraping dynamic web pages in Python](https://quanticdata.io/blog/dynamic-web-scraping-python/).

## Wait after a click: wait_for_url

```
page.click("li.next a")
page.wait_for_url("**/page/2/")      # 0.66 s
print(page.url)                      # https://quotes.toscrape.com/page/2/
```

After a click that navigates, `wait_for_url` with a glob pattern waits until the address changes; in our run it returned in 0.66 s. Follow it with an element wait when you need the new page's content, since a changed address does not mean the data has arrived.

**Try it on your own targets.** Every QuanticData account gets $2 of free API usage per month.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-inline&utm_content=playwright-wait-for-page-load) · [Explore Web Scraping API](https://quanticdata.io/web-scraping-api/)

## Why not just sleep?

`page.wait_for_timeout(3000)` paused three seconds and the page still had 0 quotes: the data came after about ten. A fixed sleep is either too short, and you scrape an empty page, or too long, and every page costs the full delay. Keep sleeps for debugging. The same goes for `time.sleep()` in Selenium, where WebDriverWait plays the role of wait_for_selector (see [Selenium find_element](https://quanticdata.io/blog/selenium-find-element/)).

## Which wait for which job

- **You scrape a list or a detail block**: `goto(url, wait_until="domcontentloaded")`, then `wait_for_selector` on the block. It returned the moment our quotes appeared and never earlier.
- **You need every item, not the first**: `wait_for_function` with a count, or wait for a "last item" or footer element that renders after the list.
- **The page loads its data from an API**: `expect_response`, and read the JSON instead of the DOM.
- **You clicked and the page changes**: `wait_for_url`, then an element wait on the new page.
- **You only need the HTML the server sent**: the default `load` is enough, and a plain HTTP client would be cheaper still.

Each of these waits for evidence that the thing you want exists. That is the whole rule: a page is loaded, for a scraper, when the data is on it.

## Timeouts

```
try:
    page.wait_for_selector("div.quote", timeout=2000)
except PlaywrightTimeoutError as e:
    print(e)   # Page.wait_for_selector: Timeout 2000ms exceeded.

page.set_default_timeout(45000)   # for every wait on this page
```

Waits default to 30 seconds; when one runs out, Playwright raises "Timeout 30000ms exceeded". Import the error with `from playwright.sync_api import TimeoutError as PlaywrightTimeoutError`. When a wait times out, take a screenshot before closing, `page.screenshot(path="debug.png", full_page=True)`: it usually shows a consent banner, an error page or a block page where you expected content. We saved one of the rendered page and one of a single quote with `locator.screenshot()`.

## Waiting through a proxy

Pass the proxy once in `chromium.launch(proxy={"server": ..., "username": ..., "password": ...})`; see [Playwright proxy setup](https://quanticdata.io/blog/playwright-proxy/). QuanticData [residential proxies](https://quanticdata.io/residential-proxies/) give a home IP by country, with a session ID in the username, and [mobile proxies](https://quanticdata.io/mobile-proxies/) put the browser on a carrier network. When you need rendered pages at volume without running browsers, our [web scraping API](https://quanticdata.io/web-scraping-api/) renders them for you. The rest of a Playwright scraper is in [Playwright for scraping](https://quanticdata.io/blog/how-to-use-playwright-for-scraping/).

### Sources & further reading

- [Playwright for Python: Page.goto (wait_until)](https://playwright.dev/python/docs/api/class-page#page-goto)
- [Playwright for Python: Auto-waiting](https://playwright.dev/python/docs/actionability)
- [Playwright for Python: Page.expect_response](https://playwright.dev/python/docs/api/class-page#page-wait-for-response)
- [Playwright for Python: Assertions](https://playwright.dev/python/docs/test-assertions)

## FAQ

Quick answers on playwright wait for page to load.

[Something else? Ask us](mailto:hello@quanticdata.io)

### How do I wait for a page to load in Playwright Python?

`page.goto(url)` waits for the load event by default. To wait for the content you need, call `page.wait_for_selector("css")` or `expect(locator).to_be_visible()` after it. In our test, load returned with 0 items and wait_for_selector with all 10.

### Should I use networkidle in Playwright?

Rarely. On our delayed page networkidle returned in 1.67 s before any data appeared, and the Playwright documentation marks it as discouraged. Wait for an element or a response instead.

### How do I wait for an element to be visible in Playwright?

`page.wait_for_selector("div.quote")`, `page.locator("div.quote").first.wait_for(state="visible")` or `expect(locator).to_be_visible()`. All three returned in 10 to 11.3 s on our test page, once the quotes existed.

### How do I wait for an API response in Playwright?

Wrap the action in `with page.expect_response(lambda r: "/api/" in r.url) as info:`, then read `info.value.json()`. On our scroll page it returned page 1 with 10 quotes.

### How do I change the timeout in Playwright?

Pass `timeout=` in milliseconds to a single call, or call `page.set_default_timeout(45000)` for the page. A wait with timeout 2000 raised "Timeout 2000ms exceeded" in our test.

## Run Playwright from a home or mobile IP

Residential and mobile proxies with username and password for chromium.launch, and a session ID in the username.

[Start free — $2/month included](https://quanticdata.io/signup/?utm_source=blog&utm_medium=website&utm_campaign=blog-end&utm_content=playwright-wait-for-page-load) · [Explore Web Scraping API](https://quanticdata.io/web-scraping-api/)

## Related reading

- [Playwright Screenshot: Full Page, Element](https://quanticdata.io/blog/playwright-screenshot/): Guides · page.screenshot({ path }) captures the viewport, fullPage: true the whole page, and locator.screenshot() one element. Below: every option run with Playwright 1.61.1, with the real file sizes (a full page dropped from 625254 bytes as PNG to 170638 as JPEG at quality 50), masking, hiding elements with style, retina and phone captures, and screenshots through residential and mobile proxies.
- [Scraping Dynamic Web Pages in Python](https://quanticdata.io/blog/dynamic-web-scraping-python/): Guides · A dynamic page sends an almost empty HTML shell and fills it with JavaScript, so requests and Beautiful Soup see nothing. Look for the data first (a JSON block in a script tag or an API call), and render with Playwright or Selenium only when there is none. We ran all three on one page.
- [Playwright Test Timeout: Defaults and Config](https://quanticdata.io/blog/playwright-test-timeout/): Guides · Playwright Test stops a test after 30 seconds and an assertion after 5 seconds by default; actions and navigations have their own optional limits. We reproduced each timeout error on 20 November 2026 against a deliberately slow local server, then fixed each one with the setting made for it.

---

Source: https://quanticdata.io/blog/playwright-wait-for-page-load/ · Site index for AI: https://quanticdata.io/llms.txt
