page.get_by_text(re.compile("^hello$", re.IGNORECASE))
**Arguments**
* `text` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [Pattern](https://docs.python.org/3/library/re.html "Pattern")[#](#page-get-by-text-option-text)
Text to locate the element for.
* `exact` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-get-by-text-option-exact)
Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a regular expression. Note that exact match still trims whitespace.
**Returns**
* [Locator](/python/docs/api/class-locator "Locator")[#](#page-get-by-text-return)
**Details**
Matching by text always normalizes whitespace, even with exact match. For example, it turns multiple spaces into one, turns line breaks into spaces and ignores leading and trailing whitespace.
Input elements of the type `button` and `submit` are matched by their `value` instead of the text content. For example, locating by text `"Log in"` matches `
`.
* * *
### get\_by\_title[](#page-get-by-title "Direct link to get_by_title")
Added in: v1.27 page.get\_by\_title
Allows locating elements by their title attribute.
**Usage**
Consider the following DOM structure.
25 issues
You can check the issues count after locating it by the title text:
* Sync
* Async
expect(page.get_by_title("Issues count")).to_have_text("25 issues")
await expect(page.get_by_title("Issues count")).to_have_text("25 issues")
**Arguments**
* `text` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [Pattern](https://docs.python.org/3/library/re.html "Pattern")[#](#page-get-by-title-option-text)
Text to locate the element for.
* `exact` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-get-by-title-option-exact)
Whether to find an exact match: case-sensitive and whole-string. Default to false. Ignored when locating by a regular expression. Note that exact match still trims whitespace.
**Returns**
* [Locator](/python/docs/api/class-locator "Locator")[#](#page-get-by-title-return)
* * *
### go\_back[](#page-go-back "Direct link to go_back")
Added before v1.9 page.go\_back
Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If cannot go back, returns `null`.
Navigate to the previous page in history.
**Usage**
page.go_back()page.go_back(**kwargs)
**Arguments**
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-go-back-option-timeout)
Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_navigation\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.set\_default\_navigation\_timeout()](/python/docs/api/class-page#page-set-default-navigation-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
* `wait_until` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-go-back-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None") | [Response](/python/docs/api/class-response "Response")[#](#page-go-back-return)
* * *
### go\_forward[](#page-go-forward "Direct link to go_forward")
Added before v1.9 page.go\_forward
Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. If cannot go forward, returns `null`.
Navigate to the next page in history.
**Usage**
page.go_forward()page.go_forward(**kwargs)
**Arguments**
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-go-forward-option-timeout)
Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_navigation\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.set\_default\_navigation\_timeout()](/python/docs/api/class-page#page-set-default-navigation-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
* `wait_until` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-go-forward-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None") | [Response](/python/docs/api/class-response "Response")[#](#page-go-forward-return)
* * *
### goto[](#page-goto "Direct link to goto")
Added before v1.9 page.goto
Returns the main resource response. In case of multiple redirects, the navigation will resolve with the first non-redirect response.
The method will throw an error if:
* there's an SSL error (e.g. in case of self-signed certificates).
* target URL is invalid.
* the [timeout](/python/docs/api/class-page#page-goto-option-timeout) is exceeded during navigation.
* the remote server does not respond or is unreachable.
* the main resource failed to load.
The method will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling [response.status](/python/docs/api/class-response#response-status).
note
The method either throws an error or returns a main resource response. The only exceptions are navigation to `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
note
Headless mode doesn't support navigation to a PDF document. See the [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
**Usage**
page.goto(url)page.goto(url, **kwargs)
**Arguments**
* `url` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-goto-option-url)
URL to navigate page to. The url should include scheme, e.g. `https://`. When a [base\_url](/python/docs/api/class-browser#browser-new-context-option-base-url) via the context options was provided and the passed URL is a path, it gets merged via the [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor.
* `referer` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") _(optional)_[#](#page-goto-option-referer)
Referer header value. If provided it will take preference over the referer header value set by [page.set\_extra\_http\_headers()](/python/docs/api/class-page#page-set-extra-http-headers).
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-goto-option-timeout)
Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_navigation\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.set\_default\_navigation\_timeout()](/python/docs/api/class-page#page-set-default-navigation-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
* `wait_until` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-goto-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None") | [Response](/python/docs/api/class-response "Response")[#](#page-goto-return)
* * *
### locator[](#page-locator "Direct link to locator")
Added in: v1.14 page.locator
The method returns an element locator that can be used to perform actions on this page / frame. Locator is resolved to the element immediately before performing an action, so a series of actions on the same locator can in fact be performed on different DOM elements. That would happen if the DOM structure between those actions has changed.
[Learn more about locators](/python/docs/locators).
**Usage**
page.locator(selector)page.locator(selector, **kwargs)
**Arguments**
* `selector` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-locator-option-selector)
A selector to use when resolving DOM element.
* `has` [Locator](/python/docs/api/class-locator "Locator") _(optional)_[#](#page-locator-option-has)
Narrows down the results of the method to those which contain elements matching this relative locator. For example, `article` that has `text=Playwright` matches `
Playwright
`.
Inner locator **must be relative** to the outer locator and is queried starting with the outer locator match, not the document root. For example, you can find `content` that has `div` in `
Playwright
`. However, looking for `content` that has `article div` will fail, because the inner locator must be relative and should not use any elements outside the `content`.
Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator](/python/docs/api/class-framelocator "FrameLocator")s.
* `has_not` [Locator](/python/docs/api/class-locator "Locator") _(optional)_ Added in: v1.33[#](#page-locator-option-has-not)
Matches elements that do not contain an element that matches an inner locator. Inner locator is queried against the outer one. For example, `article` that does not have `div` matches `
Playwright `.
Note that outer and inner locators must belong to the same frame. Inner locator must not contain [FrameLocator](/python/docs/api/class-framelocator "FrameLocator")s.
* `has_not_text` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [Pattern](https://docs.python.org/3/library/re.html "Pattern") _(optional)_ Added in: v1.33[#](#page-locator-option-has-not-text)
Matches elements that do not contain specified text somewhere inside, possibly in a child or a descendant element. When passed a \[string\], matching is case-insensitive and searches for a substring.
* `has_text` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [Pattern](https://docs.python.org/3/library/re.html "Pattern") _(optional)_[#](#page-locator-option-has-text)
Matches elements containing specified text somewhere inside, possibly in a child or a descendant element. When passed a \[string\], matching is case-insensitive and searches for a substring. For example, `"Playwright"` matches `
Playwright
`.
**Returns**
* [Locator](/python/docs/api/class-locator "Locator")[#](#page-locator-return)
* * *
### opener[](#page-opener "Direct link to opener")
Added before v1.9 page.opener
Returns the opener for popup pages and `null` for others. If the opener has been closed already the returns `null`.
**Usage**
page.opener()
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None") | [Page](/python/docs/api/class-page "Page")[#](#page-opener-return)
* * *
### page\_errors[](#page-page-errors "Direct link to page_errors")
Added in: v1.56 page.page\_errors
Returns up to (currently) 200 last page errors from this page. See [page.on("pageerror")](/python/docs/api/class-page#page-event-page-error) for more details.
**Usage**
page.page_errors()
**Returns**
* [List](https://docs.python.org/3/library/typing.html#typing.List "List")\[[Error](/python/docs/api/class-error "Error")\][#](#page-page-errors-return)
* * *
### pause[](#page-pause "Direct link to pause")
Added in: v1.9 page.pause
Pauses script execution. Playwright will stop executing the script and wait for the user to either press the 'Resume' button in the page overlay or to call `playwright.resume()` in the DevTools console.
User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from the place it was paused.
note
This method requires Playwright to be started in a headed mode, with a falsy [headless](/python/docs/api/class-browsertype#browser-type-launch-option-headless) option.
**Usage**
page.pause()
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-pause-return)
* * *
### pdf[](#page-pdf "Direct link to pdf")
Added before v1.9 page.pdf
Returns the PDF buffer.
`page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call [page.emulate\_media()](/python/docs/api/class-page#page-emulate-media) before calling `page.pdf()`:
note
By default, `page.pdf()` generates a pdf with modified colors for printing. Use the [`-webkit-print-color-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust) property to force rendering of exact colors.
**Usage**
* Sync
* Async
# generates a pdf with "screen" media type.page.emulate_media(media="screen")page.pdf(path="page.pdf")
# generates a pdf with "screen" media type.await page.emulate_media(media="screen")await page.pdf(path="page.pdf")
The [width](/python/docs/api/class-page#page-pdf-option-width), [height](/python/docs/api/class-page#page-pdf-option-height), and [margin](/python/docs/api/class-page#page-pdf-option-margin) options accept values labeled with units. Unlabeled values are treated as pixels.
A few examples:
* `page.pdf({width: 100})` - prints with width set to 100 pixels
* `page.pdf({width: '100px'})` - prints with width set to 100 pixels
* `page.pdf({width: '10cm'})` - prints with width set to 10 centimeters.
All possible units are:
* `px` - pixel
* `in` - inch
* `cm` - centimeter
* `mm` - millimeter
The [format](/python/docs/api/class-page#page-pdf-option-format) options are:
* `Letter`: 8.5in x 11in
* `Legal`: 8.5in x 14in
* `Tabloid`: 11in x 17in
* `Ledger`: 17in x 11in
* `A0`: 33.1in x 46.8in
* `A1`: 23.4in x 33.1in
* `A2`: 16.54in x 23.4in
* `A3`: 11.7in x 16.54in
* `A4`: 8.27in x 11.7in
* `A5`: 5.83in x 8.27in
* `A6`: 4.13in x 5.83in
note
[header\_template](/python/docs/api/class-page#page-pdf-option-header-template) and [footer\_template](/python/docs/api/class-page#page-pdf-option-footer-template) markup have the following limitations: > 1. Script tags inside templates are not evaluated. > 2. Page styles are not visible inside templates.
**Arguments**
* `display_header_footer` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-pdf-option-display-header-footer)
Display header and footer. Defaults to `false`.
* `footer_template` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") _(optional)_[#](#page-pdf-option-footer-template)
HTML template for the print footer. Should use the same format as the [header\_template](/python/docs/api/class-page#page-pdf-option-header-template).
* `format` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") _(optional)_[#](#page-pdf-option-format)
Paper format. If set, takes priority over [width](/python/docs/api/class-page#page-pdf-option-width) or [height](/python/docs/api/class-page#page-pdf-option-height) options. Defaults to 'Letter'.
* `header_template` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") _(optional)_[#](#page-pdf-option-header-template)
HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
* `'date'` formatted print date
* `'title'` document title
* `'url'` document location
* `'pageNumber'` current page number
* `'totalPages'` total pages in the document
* `height` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-pdf-option-height)
Paper height, accepts values labeled with units.
* `landscape` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-pdf-option-landscape)
Paper orientation. Defaults to `false`.
* `margin` [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "Dict") _(optional)_[#](#page-pdf-option-margin)
* `top` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_
Top margin, accepts values labeled with units. Defaults to `0`.
* `right` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_
Right margin, accepts values labeled with units. Defaults to `0`.
* `bottom` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_
Bottom margin, accepts values labeled with units. Defaults to `0`.
* `left` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_
Left margin, accepts values labeled with units. Defaults to `0`.
Paper margins, defaults to none.
* `outline` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_ Added in: v1.42[#](#page-pdf-option-outline)
Whether or not to embed the document outline into the PDF. Defaults to `false`.
* `page_ranges` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") _(optional)_[#](#page-pdf-option-page-ranges)
Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
* `path` [Union](https://docs.python.org/3/library/typing.html#typing.Union "Union")\[[str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str"), [pathlib.Path](https://realpython.com/python-pathlib/ "pathlib.Path")\] _(optional)_[#](#page-pdf-option-path)
The file path to save the PDF to. If [path](/python/docs/api/class-page#page-pdf-option-path) is a relative path, then it is resolved relative to the current working directory. If no path is provided, the PDF won't be saved to the disk.
* `prefer_css_page_size` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-pdf-option-prefer-css-page-size)
Give any CSS `@page` size declared in the page priority over what is declared in [width](/python/docs/api/class-page#page-pdf-option-width) and [height](/python/docs/api/class-page#page-pdf-option-height) or [format](/python/docs/api/class-page#page-pdf-option-format) options. Defaults to `false`, which will scale the content to fit the paper size.
* `print_background` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-pdf-option-print-background)
Print background graphics. Defaults to `false`.
* `scale` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-pdf-option-scale)
Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.
* `tagged` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_ Added in: v1.42[#](#page-pdf-option-tagged)
Whether or not to generate tagged (accessible) PDF. Defaults to `false`.
* `width` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-pdf-option-width)
Paper width, accepts values labeled with units.
**Returns**
* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "bytes")[#](#page-pdf-return)
* * *
### reload[](#page-reload "Direct link to reload")
Added before v1.9 page.reload
This method reloads the current page, in the same way as if the user had triggered a browser refresh. Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
**Usage**
page.reload()page.reload(**kwargs)
**Arguments**
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-reload-option-timeout)
Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_navigation\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.set\_default\_navigation\_timeout()](/python/docs/api/class-page#page-set-default-navigation-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
* `wait_until` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-reload-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None") | [Response](/python/docs/api/class-response "Response")[#](#page-reload-return)
* * *
### remove\_locator\_handler[](#page-remove-locator-handler "Direct link to remove_locator_handler")
Added in: v1.44 page.remove\_locator\_handler
Removes all locator handlers added by [page.add\_locator\_handler()](/python/docs/api/class-page#page-add-locator-handler) for a specific locator.
**Usage**
page.remove_locator_handler(locator)
**Arguments**
* `locator` [Locator](/python/docs/api/class-locator "Locator")[#](#page-remove-locator-handler-option-locator)
Locator passed to [page.add\_locator\_handler()](/python/docs/api/class-page#page-add-locator-handler).
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-remove-locator-handler-return)
* * *
### request\_gc[](#page-request-gc "Direct link to request_gc")
Added in: v1.48 page.request\_gc
Request the page to perform garbage collection. Note that there is no guarantee that all unreachable objects will be collected.
This is useful to help detect memory leaks. For example, if your page has a large object `'suspect'` that might be leaked, you can check that it does not leak by using a [`WeakRef`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef).
* Sync
* Async
# 1. In your page, save a WeakRef for the "suspect".page.evaluate("globalThis.suspectWeakRef = new WeakRef(suspect)")# 2. Request garbage collection.page.request_gc()# 3. Check that weak ref does not deref to the original object.assert page.evaluate("!globalThis.suspectWeakRef.deref()")
# 1. In your page, save a WeakRef for the "suspect".await page.evaluate("globalThis.suspectWeakRef = new WeakRef(suspect)")# 2. Request garbage collection.await page.request_gc()# 3. Check that weak ref does not deref to the original object.assert await page.evaluate("!globalThis.suspectWeakRef.deref()")
**Usage**
page.request_gc()
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-request-gc-return)
* * *
### requests[](#page-requests "Direct link to requests")
Added in: v1.56 page.requests
Returns up to (currently) 100 last network request from this page. See [page.on("request")](/python/docs/api/class-page#page-event-request) for more details.
Returned requests should be accessed immediately, otherwise they might be collected to prevent unbounded memory growth as new requests come in. Once collected, retrieving most information about the request is impossible.
Note that requests reported through the [page.on("request")](/python/docs/api/class-page#page-event-request) request are not collected, so there is a trade off between efficient memory usage with [page.requests()](/python/docs/api/class-page#page-requests) and the amount of available information reported through [page.on("request")](/python/docs/api/class-page#page-event-request).
**Usage**
page.requests()
**Returns**
* [List](https://docs.python.org/3/library/typing.html#typing.List "List")\[[Request](/python/docs/api/class-request "Request")\][#](#page-requests-return)
* * *
### route[](#page-route "Direct link to route")
Added before v1.9 page.route
Routing provides the capability to modify network requests that are made by a page.
Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
note
The handler will only be called for the first url if the response is a redirect.
note
[page.route()](/python/docs/api/class-page#page-route) will not intercept requests intercepted by Service Worker. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting [service\_workers](/python/docs/api/class-browser#browser-new-context-option-service-workers) to `'block'`.
note
[page.route()](/python/docs/api/class-page#page-route) will not intercept the first request of a popup page. Use [browser\_context.route()](/python/docs/api/class-browsercontext#browser-context-route) instead.
**Usage**
An example of a naive handler that aborts all image requests:
* Sync
* Async
page = browser.new_page()page.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())page.goto("https://example.com")browser.close()
page = await browser.new_page()await page.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())await page.goto("https://example.com")await browser.close()
or the same snippet using a regex pattern instead:
* Sync
* Async
page = browser.new_page()page.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())page.goto("https://example.com")browser.close()
page = await browser.new_page()await page.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())await page.goto("https://example.com")await browser.close()
It is possible to examine the request to decide the route action. For example, mocking all requests that contain some post data, and leaving all other requests as is:
* Sync
* Async
def handle_route(route: Route): if ("my-string" in route.request.post_data): route.fulfill(body="mocked-data") else: route.continue_()page.route("/api/**", handle_route)
async def handle_route(route: Route): if ("my-string" in route.request.post_data): await route.fulfill(body="mocked-data") else: await route.continue_()await page.route("/api/**", handle_route)
Page routes take precedence over browser context routes (set up with [browser\_context.route()](/python/docs/api/class-browsercontext#browser-context-route)) when request matches both handlers.
To remove a route with its handler you can use [page.unroute()](/python/docs/api/class-page#page-unroute).
note
Enabling routing disables http cache.
**Arguments**
* `url` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [Pattern](https://docs.python.org/3/library/re.html "Pattern") | [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "Callable")\[[URL](https://en.wikipedia.org/wiki/URL "URL")\]:[bool](https://docs.python.org/3/library/stdtypes.html "bool")[#](#page-route-option-url)
A glob pattern, regex pattern, or predicate that receives a [URL](https://en.wikipedia.org/wiki/URL "URL") to match during routing. If [base\_url](/python/docs/api/class-browser#browser-new-context-option-base-url) is set in the context options and the provided URL is a string that does not start with `*`, it is resolved using the [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor.
* `handler` [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "Callable")\[[Route](/python/docs/api/class-route "Route"), [Request](/python/docs/api/class-request "Request")\]:[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")\[[Any](https://docs.python.org/3/library/typing.html#typing.Any "Any")\] | [Any](https://docs.python.org/3/library/typing.html#typing.Any "Any")[#](#page-route-option-handler)
handler function to route the request.
* `times` [int](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "int") _(optional)_ Added in: v1.15[#](#page-route-option-times)
How often a route should be used. By default it will be used every time.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-route-return)
* * *
### route\_from\_har[](#page-route-from-har "Direct link to route_from_har")
Added in: v1.23 page.route\_from\_har
If specified the network requests that are made in the page will be served from the HAR file. Read more about [Replaying from HAR](/python/docs/mock#replaying-from-har).
Playwright will not serve requests intercepted by Service Worker from the HAR file. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting [service\_workers](/python/docs/api/class-browser#browser-new-context-option-service-workers) to `'block'`.
**Usage**
page.route_from_har(har)page.route_from_har(har, **kwargs)
**Arguments**
* `har` [Union](https://docs.python.org/3/library/typing.html#typing.Union "Union")\[[str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str"), [pathlib.Path](https://realpython.com/python-pathlib/ "pathlib.Path")\][#](#page-route-from-har-option-har)
Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a relative path, then it is resolved relative to the current working directory.
* `not_found` "abort" | "fallback" _(optional)_[#](#page-route-from-har-option-not-found)
* If set to 'abort' any request not found in the HAR file will be aborted.
* If set to 'fallback' missing requests will be sent to the network.
Defaults to abort.
* `update` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-route-from-har-option-update)
If specified, updates the given HAR with the actual network information instead of serving from file. The file is written to disk when [browser\_context.close()](/python/docs/api/class-browsercontext#browser-context-close) is called.
* `update_content` "embed" | "attach" _(optional)_ Added in: v1.32[#](#page-route-from-har-option-update-content)
Optional setting to control resource content management. If `attach` is specified, resources are persisted as separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file.
* `update_mode` "full" | "minimal" _(optional)_ Added in: v1.32[#](#page-route-from-har-option-update-mode)
When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `minimal`.
* `url` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [Pattern](https://docs.python.org/3/library/re.html "Pattern") _(optional)_[#](#page-route-from-har-option-url)
A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern will be served from the HAR file. If not specified, all requests are served from the HAR file.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-route-from-har-return)
* * *
### route\_web\_socket[](#page-route-web-socket "Direct link to route_web_socket")
Added in: v1.48 page.route\_web\_socket
This method allows to modify websocket connections that are made by the page.
Note that only `WebSocket`s created after this method was called will be routed. It is recommended to call this method before navigating the page.
**Usage**
Below is an example of a simple mock that responds to a single message. See [WebSocketRoute](/python/docs/api/class-websocketroute "WebSocketRoute") for more details and examples.
* Sync
* Async
def message_handler(ws: WebSocketRoute, message: Union[str, bytes]): if message == "request": ws.send("response")def handler(ws: WebSocketRoute): ws.on_message(lambda message: message_handler(ws, message))page.route_web_socket("/ws", handler)
def message_handler(ws: WebSocketRoute, message: Union[str, bytes]): if message == "request": ws.send("response")def handler(ws: WebSocketRoute): ws.on_message(lambda message: message_handler(ws, message))await page.route_web_socket("/ws", handler)
**Arguments**
* `url` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [Pattern](https://docs.python.org/3/library/re.html "Pattern") | [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "Callable")\[[URL](https://en.wikipedia.org/wiki/URL "URL")\]:[bool](https://docs.python.org/3/library/stdtypes.html "bool")[#](#page-route-web-socket-option-url)
Only WebSockets with the url matching this pattern will be routed. A string pattern can be relative to the [base\_url](/python/docs/api/class-browser#browser-new-context-option-base-url) context option.
* `handler` [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "Callable")\[[WebSocketRoute](/python/docs/api/class-websocketroute "WebSocketRoute")\]:[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")\[[Any](https://docs.python.org/3/library/typing.html#typing.Any "Any")\] | [Any](https://docs.python.org/3/library/typing.html#typing.Any "Any")[#](#page-route-web-socket-option-handler)
Handler function to route the WebSocket.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-route-web-socket-return)
* * *
### screenshot[](#page-screenshot "Direct link to screenshot")
Added before v1.9 page.screenshot
Returns the buffer with the captured screenshot.
**Usage**
page.screenshot()page.screenshot(**kwargs)
**Arguments**
* `animations` "disabled" | "allow" _(optional)_[#](#page-screenshot-option-animations)
When set to `"disabled"`, stops CSS animations, CSS transitions and Web Animations. Animations get different treatment depending on their duration:
* finite animations are fast-forwarded to completion, so they'll fire `transitionend` event.
* infinite animations are canceled to initial state, and then played over after the screenshot.
Defaults to `"allow"` that leaves animations untouched.
* `caret` "hide" | "initial" _(optional)_[#](#page-screenshot-option-caret)
When set to `"hide"`, screenshot will hide text caret. When set to `"initial"`, text caret behavior will not be changed. Defaults to `"hide"`.
* `clip` [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "Dict") _(optional)_[#](#page-screenshot-option-clip)
* `x` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")
x-coordinate of top-left corner of clip area
* `y` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")
y-coordinate of top-left corner of clip area
* `width` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")
width of clipping area
* `height` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")
height of clipping area
An object which specifies clipping of the resulting image.
* `full_page` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-screenshot-option-full-page)
When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to `false`.
* `mask` [List](https://docs.python.org/3/library/typing.html#typing.List "List")\[[Locator](/python/docs/api/class-locator "Locator")\] _(optional)_[#](#page-screenshot-option-mask)
Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box `#FF00FF` (customized by [mask\_color](/python/docs/api/class-page#page-screenshot-option-mask-color)) that completely covers its bounding box. The mask is also applied to invisible elements, see [Matching only visible elements](/python/docs/locators#matching-only-visible-elements) to disable that.
* `mask_color` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") _(optional)_ Added in: v1.35[#](#page-screenshot-option-mask-color)
Specify the color of the overlay box for masked elements, in [CSS color format](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value). Default color is pink `#FF00FF`.
* `omit_background` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-screenshot-option-omit-background)
Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images. Defaults to `false`.
* `path` [Union](https://docs.python.org/3/library/typing.html#typing.Union "Union")\[[str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str"), [pathlib.Path](https://realpython.com/python-pathlib/ "pathlib.Path")\] _(optional)_[#](#page-screenshot-option-path)
The file path to save the image to. The screenshot type will be inferred from file extension. If [path](/python/docs/api/class-page#page-screenshot-option-path) is a relative path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to the disk.
* `quality` [int](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "int") _(optional)_[#](#page-screenshot-option-quality)
The quality of the image, between 0-100. Not applicable to `png` images.
* `scale` "css" | "device" _(optional)_[#](#page-screenshot-option-scale)
When set to `"css"`, screenshot will have a single pixel per each css pixel on the page. For high-dpi devices, this will keep screenshots small. Using `"device"` option will produce a single pixel per each device pixel, so screenshots of high-dpi devices will be twice as large or even larger.
Defaults to `"device"`.
* `style` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") _(optional)_ Added in: v1.41[#](#page-screenshot-option-style)
Text of the stylesheet to apply while making the screenshot. This is where you can hide dynamic elements, make elements invisible or change their properties to help you creating repeatable screenshots. This stylesheet pierces the Shadow DOM and applies to the inner frames.
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-screenshot-option-timeout)
Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
* `type` "png" | "jpeg" _(optional)_[#](#page-screenshot-option-type)
Specify screenshot type, defaults to `png`.
**Returns**
* [bytes](https://docs.python.org/3/library/stdtypes.html#bytes "bytes")[#](#page-screenshot-return)
* * *
### set\_content[](#page-set-content "Direct link to set_content")
Added before v1.9 page.set\_content
This method internally calls [document.write()](https://developer.mozilla.org/en-US/docs/Web/API/Document/write), inheriting all its specific characteristics and behaviors.
**Usage**
page.set_content(html)page.set_content(html, **kwargs)
**Arguments**
* `html` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-set-content-option-html)
HTML markup to assign to the page.
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-set-content-option-timeout)
Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_navigation\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.set\_default\_navigation\_timeout()](/python/docs/api/class-page#page-set-default-navigation-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
* `wait_until` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-set-content-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-set-content-return)
* * *
### set\_default\_navigation\_timeout[](#page-set-default-navigation-timeout "Direct link to set_default_navigation_timeout")
Added before v1.9 page.set\_default\_navigation\_timeout
This setting will change the default maximum navigation time for the following methods and related shortcuts:
* [page.go\_back()](/python/docs/api/class-page#page-go-back)
* [page.go\_forward()](/python/docs/api/class-page#page-go-forward)
* [page.goto()](/python/docs/api/class-page#page-goto)
* [page.reload()](/python/docs/api/class-page#page-reload)
* [page.set\_content()](/python/docs/api/class-page#page-set-content)
* [page.expect\_navigation()](/python/docs/api/class-page#page-wait-for-navigation)
* [page.wait\_for\_url()](/python/docs/api/class-page#page-wait-for-url)
note
[page.set\_default\_navigation\_timeout()](/python/docs/api/class-page#page-set-default-navigation-timeout) takes priority over [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout), [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout) and [browser\_context.set\_default\_navigation\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout).
**Usage**
page.set_default_navigation_timeout(timeout)
**Arguments**
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")[#](#page-set-default-navigation-timeout-option-timeout)
Maximum navigation time in milliseconds
* * *
### set\_default\_timeout[](#page-set-default-timeout "Direct link to set_default_timeout")
Added before v1.9 page.set\_default\_timeout
This setting will change the default maximum time for all the methods accepting [timeout](/python/docs/api/class-page#page-set-default-timeout-option-timeout) option.
note
[page.set\_default\_navigation\_timeout()](/python/docs/api/class-page#page-set-default-navigation-timeout) takes priority over [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout).
**Usage**
page.set_default_timeout(timeout)
**Arguments**
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")[#](#page-set-default-timeout-option-timeout)
Maximum time in milliseconds. Pass `0` to disable timeout.
* * *
### set\_extra\_http\_headers[](#page-set-extra-http-headers "Direct link to set_extra_http_headers")
Added before v1.9 page.set\_extra\_http\_headers
The extra HTTP headers will be sent with every request the page initiates.
note
[page.set\_extra\_http\_headers()](/python/docs/api/class-page#page-set-extra-http-headers) does not guarantee the order of headers in the outgoing requests.
**Usage**
page.set_extra_http_headers(headers)
**Arguments**
* `headers` [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "Dict")\[[str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str"), [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")\][#](#page-set-extra-http-headers-option-headers)
An object containing additional HTTP headers to be sent with every request. All header values must be strings.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-set-extra-http-headers-return)
* * *
### set\_viewport\_size[](#page-set-viewport-size "Direct link to set_viewport_size")
Added before v1.9 page.set\_viewport\_size
In the case of multiple pages in a single browser, each page can have its own viewport size. However, [browser.new\_context()](/python/docs/api/class-browser#browser-new-context) allows to set viewport size (and more) for all pages in the context at once.
[page.set\_viewport\_size()](/python/docs/api/class-page#page-set-viewport-size) will resize the page. A lot of websites don't expect phones to change size, so you should set the viewport size before navigating to the page. [page.set\_viewport\_size()](/python/docs/api/class-page#page-set-viewport-size) will also reset `screen` size, use [browser.new\_context()](/python/docs/api/class-browser#browser-new-context) with `screen` and `viewport` parameters if you need better control of these properties.
**Usage**
* Sync
* Async
page = browser.new_page()page.set_viewport_size({"width": 640, "height": 480})page.goto("https://example.com")
page = await browser.new_page()await page.set_viewport_size({"width": 640, "height": 480})await page.goto("https://example.com")
**Arguments**
* `viewport_size` [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "Dict")[#](#page-set-viewport-size-option-viewport-size)
* `width` [int](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "int")
page width in pixels.
* `height` [int](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "int")
page height in pixels.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-set-viewport-size-return)
* * *
### title[](#page-title "Direct link to title")
Added before v1.9 page.title
Returns the page's title.
**Usage**
page.title()
**Returns**
* [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-title-return)
* * *
### unroute[](#page-unroute "Direct link to unroute")
Added before v1.9 page.unroute
Removes a route created with [page.route()](/python/docs/api/class-page#page-route). When [handler](/python/docs/api/class-page#page-unroute-option-handler) is not specified, removes all routes for the [url](/python/docs/api/class-page#page-unroute-option-url).
**Usage**
page.unroute(url)page.unroute(url, **kwargs)
**Arguments**
* `url` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [Pattern](https://docs.python.org/3/library/re.html "Pattern") | [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "Callable")\[[URL](https://en.wikipedia.org/wiki/URL "URL")\]:[bool](https://docs.python.org/3/library/stdtypes.html "bool")[#](#page-unroute-option-url)
A glob pattern, regex pattern or predicate receiving [URL](https://en.wikipedia.org/wiki/URL "URL") to match while routing.
* `handler` [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "Callable")\[[Route](/python/docs/api/class-route "Route"), [Request](/python/docs/api/class-request "Request")\]:[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")\[[Any](https://docs.python.org/3/library/typing.html#typing.Any "Any")\] | [Any](https://docs.python.org/3/library/typing.html#typing.Any "Any") _(optional)_[#](#page-unroute-option-handler)
Optional handler function to route the request.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-unroute-return)
* * *
### unroute\_all[](#page-unroute-all "Direct link to unroute_all")
Added in: v1.41 page.unroute\_all
Removes all routes created with [page.route()](/python/docs/api/class-page#page-route) and [page.route\_from\_har()](/python/docs/api/class-page#page-route-from-har).
**Usage**
page.unroute_all()page.unroute_all(**kwargs)
**Arguments**
* `behavior` "wait" | "ignoreErrors" | "default" _(optional)_[#](#page-unroute-all-option-behavior)
Specifies whether to wait for already running handlers and what to do if they throw errors:
* `'default'` - do not wait for current handler calls (if any) to finish, if unrouted handler throws, it may result in unhandled error
* `'wait'` - wait for current handler calls (if any) to finish
* `'ignoreErrors'` - do not wait for current handler calls (if any) to finish, all errors thrown by the handlers after unrouting are silently caught
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-unroute-all-return)
* * *
### wait\_for\_event[](#page-wait-for-event-2 "Direct link to wait_for_event")
Added before v1.9 page.wait\_for\_event
note
In most cases, you should use [page.expect\_event()](/python/docs/api/class-page#page-wait-for-event).
Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is closed before the `event` is fired.
**Usage**
page.wait_for_event(event)page.wait_for_event(event, **kwargs)
**Arguments**
* `event` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-wait-for-event-2-option-event)
Event name, same one typically passed into `*.on(event)`.
* `predicate` [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "Callable") _(optional)_[#](#page-wait-for-event-2-option-predicate)
Receives the event data and resolves to truthy value when the waiting should resolve.
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-wait-for-event-2-option-timeout)
Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout).
**Returns**
* [Any](https://docs.python.org/3/library/typing.html#typing.Any "Any")[#](#page-wait-for-event-2-return)
* * *
### wait\_for\_function[](#page-wait-for-function "Direct link to wait_for_function")
Added before v1.9 page.wait\_for\_function
Returns when the [expression](/python/docs/api/class-page#page-wait-for-function-option-expression) returns a truthy value. It resolves to a JSHandle of the truthy value.
**Usage**
The [page.wait\_for\_function()](/python/docs/api/class-page#page-wait-for-function) can be used to observe viewport size change:
* Sync
* Async
from playwright.sync_api import sync_playwright, Playwrightdef run(playwright: Playwright): webkit = playwright.webkit browser = webkit.launch() page = browser.new_page() page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);") page.wait_for_function("() => window.x > 0") browser.close()with sync_playwright() as playwright: run(playwright)
import asynciofrom playwright.async_api import async_playwright, Playwrightasync def run(playwright: Playwright): webkit = playwright.webkit browser = await webkit.launch() page = await browser.new_page() await page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);") await page.wait_for_function("() => window.x > 0") await browser.close()async def main(): async with async_playwright() as playwright: await run(playwright)asyncio.run(main())
To pass an argument to the predicate of [page.wait\_for\_function()](/python/docs/api/class-page#page-wait-for-function) function:
* Sync
* Async
selector = ".foo"page.wait_for_function("selector => !!document.querySelector(selector)", selector)
selector = ".foo"await page.wait_for_function("selector => !!document.querySelector(selector)", selector)
**Arguments**
* `expression` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-wait-for-function-option-expression)
JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.
* `arg` [EvaluationArgument](/python/docs/evaluating#evaluation-argument "EvaluationArgument") _(optional)_[#](#page-wait-for-function-option-arg)
Optional argument to pass to [expression](/python/docs/api/class-page#page-wait-for-function-option-expression).
* `polling` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") | "raf" _(optional)_[#](#page-wait-for-function-option-polling)
If [polling](/python/docs/api/class-page#page-wait-for-function-option-polling) is `'raf'`, then [expression](/python/docs/api/class-page#page-wait-for-function-option-expression) is constantly executed in `requestAnimationFrame` callback. If [polling](/python/docs/api/class-page#page-wait-for-function-option-polling) is a number, then it is treated as an interval in milliseconds at which the function would be executed. Defaults to `raf`.
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-wait-for-function-option-timeout)
Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
**Returns**
* [JSHandle](/python/docs/api/class-jshandle "JSHandle")[#](#page-wait-for-function-return)
* * *
### wait\_for\_load\_state[](#page-wait-for-load-state "Direct link to wait_for_load_state")
Added before v1.9 page.wait\_for\_load\_state
Returns when the required load state has been reached.
This resolves when the page reaches a required load state, `load` by default. The navigation must have been committed when this method is called. If current document has already reached the required state, resolves immediately.
note
Most of the time, this method is not needed because Playwright [auto-waits before every action](/python/docs/actionability).
**Usage**
* Sync
* Async
page.get_by_role("button").click() # click triggers navigation.page.wait_for_load_state() # the promise resolves after "load" event.
await page.get_by_role("button").click() # click triggers navigation.await page.wait_for_load_state() # the promise resolves after "load" event.
* Sync
* Async
with page.expect_popup() as page_info: page.get_by_role("button").click() # click triggers a popup.popup = page_info.value# Wait for the "DOMContentLoaded" event.popup.wait_for_load_state("domcontentloaded")print(popup.title()) # popup is ready to use.
async with page.expect_popup() as page_info: await page.get_by_role("button").click() # click triggers a popup.popup = await page_info.value# Wait for the "DOMContentLoaded" event.await popup.wait_for_load_state("domcontentloaded")print(await popup.title()) # popup is ready to use.
**Arguments**
* `state` "load" | "domcontentloaded" | "networkidle" _(optional)_[#](#page-wait-for-load-state-option-state)
Optional load state to wait for, defaults to `load`. If the state has been already reached while loading current document, the method resolves immediately. Can be one of:
* `'load'` - wait for the `load` event to be fired.
* `'domcontentloaded'` - wait for the `DOMContentLoaded` event to be fired.
* `'networkidle'` - **DISCOURAGED** wait until there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-wait-for-load-state-option-timeout)
Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_navigation\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.set\_default\_navigation\_timeout()](/python/docs/api/class-page#page-set-default-navigation-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-wait-for-load-state-return)
* * *
### wait\_for\_url[](#page-wait-for-url "Direct link to wait_for_url")
Added in: v1.11 page.wait\_for\_url
Waits for the main frame to navigate to the given URL.
**Usage**
* Sync
* Async
page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigationpage.wait_for_url("**/target.html")
await page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigationawait page.wait_for_url("**/target.html")
**Arguments**
* `url` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [Pattern](https://docs.python.org/3/library/re.html "Pattern") | [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "Callable")\[[URL](https://en.wikipedia.org/wiki/URL "URL")\]:[bool](https://docs.python.org/3/library/stdtypes.html "bool")[#](#page-wait-for-url-option-url)
A glob pattern, regex pattern or predicate receiving [URL](https://en.wikipedia.org/wiki/URL "URL") to match while waiting for the navigation. Note that if the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to the string.
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-wait-for-url-option-timeout)
Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_navigation\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.set\_default\_navigation\_timeout()](/python/docs/api/class-page#page-set-default-navigation-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
* `wait_until` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-wait-for-url-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-wait-for-url-return)
* * *
Properties[](#properties "Direct link to Properties")
------------------------------------------------------
### clock[](#page-clock "Direct link to clock")
Added in: v1.45 page.clock
Playwright has ability to mock clock and passage of time.
**Usage**
page.clock
**Type**
* [Clock](/python/docs/api/class-clock "Clock")
* * *
### context[](#page-context "Direct link to context")
Added before v1.9 page.context
Get the browser context that the page belongs to.
**Usage**
page.context
**Returns**
* [BrowserContext](/python/docs/api/class-browsercontext "BrowserContext")[#](#page-context-return)
* * *
### frames[](#page-frames "Direct link to frames")
Added before v1.9 page.frames
An array of all frames attached to the page.
**Usage**
page.frames
**Returns**
* [List](https://docs.python.org/3/library/typing.html#typing.List "List")\[[Frame](/python/docs/api/class-frame "Frame")\][#](#page-frames-return)
* * *
### is\_closed[](#page-is-closed "Direct link to is_closed")
Added before v1.9 page.is\_closed
Indicates that the page has been closed.
**Usage**
page.is_closed()
**Returns**
* [bool](https://docs.python.org/3/library/stdtypes.html "bool")[#](#page-is-closed-return)
* * *
### keyboard[](#page-keyboard "Direct link to keyboard")
Added before v1.9 page.keyboard
**Usage**
page.keyboard
**Type**
* [Keyboard](/python/docs/api/class-keyboard "Keyboard")
* * *
### main\_frame[](#page-main-frame "Direct link to main_frame")
Added before v1.9 page.main\_frame
The page's main frame. Page is guaranteed to have a main frame which persists during navigations.
**Usage**
page.main_frame
**Returns**
* [Frame](/python/docs/api/class-frame "Frame")[#](#page-main-frame-return)
* * *
### mouse[](#page-mouse "Direct link to mouse")
Added before v1.9 page.mouse
**Usage**
page.mouse
**Type**
* [Mouse](/python/docs/api/class-mouse "Mouse")
* * *
### request[](#page-request "Direct link to request")
Added in: v1.16 page.request
API testing helper associated with this page. This method returns the same instance as [browser\_context.request](/python/docs/api/class-browsercontext#browser-context-request) on the page's context. See [browser\_context.request](/python/docs/api/class-browsercontext#browser-context-request) for more details.
**Usage**
page.request
**Type**
* [APIRequestContext](/python/docs/api/class-apirequestcontext "APIRequestContext")
* * *
### touchscreen[](#page-touchscreen "Direct link to touchscreen")
Added before v1.9 page.touchscreen
**Usage**
page.touchscreen
**Type**
* [Touchscreen](/python/docs/api/class-touchscreen "Touchscreen")
* * *
### url[](#page-url "Direct link to url")
Added before v1.9 page.url
**Usage**
page.url
**Returns**
* [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-url-return)
* * *
### video[](#page-video "Direct link to video")
Added before v1.9 page.video
Video object associated with this page.
**Usage**
page.video
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None") | [Video](/python/docs/api/class-video "Video")[#](#page-video-return)
* * *
### viewport\_size[](#page-viewport-size "Direct link to viewport_size")
Added before v1.9 page.viewport\_size
**Usage**
page.viewport_size
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None") | [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "Dict")[#](#page-viewport-size-return)
* `width` [int](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "int")
page width in pixels.
* `height` [int](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "int")
page height in pixels.
* * *
### workers[](#page-workers "Direct link to workers")
Added before v1.9 page.workers
This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) associated with the page.
note
This does not contain ServiceWorkers
**Usage**
page.workers
**Returns**
* [List](https://docs.python.org/3/library/typing.html#typing.List "List")\[[Worker](/python/docs/api/class-worker "Worker")\][#](#page-workers-return)
* * *
Events[](#events "Direct link to Events")
------------------------------------------
### on("close")[](#page-event-close "Direct link to on(\"close\")")
Added before v1.9 page.on("close")
Emitted when the page closes.
**Usage**
page.on("close", handler)
**Event data**
* [Page](/python/docs/api/class-page "Page")
* * *
### on("console")[](#page-event-console "Direct link to on(\"console\")")
Added before v1.9 page.on("console")
Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`.
The arguments passed into `console.log` are available on the [ConsoleMessage](/python/docs/api/class-consolemessage "ConsoleMessage") event handler argument.
**Usage**
* Sync
* Async
def print_args(msg): for arg in msg.args: print(arg.json_value())page.on("console", print_args)page.evaluate("console.log('hello', 5, { foo: 'bar' })")
async def print_args(msg): values = [] for arg in msg.args: values.append(await arg.json_value()) print(values)page.on("console", print_args)await page.evaluate("console.log('hello', 5, { foo: 'bar' })")
**Event data**
* [ConsoleMessage](/python/docs/api/class-consolemessage "ConsoleMessage")
* * *
### on("crash")[](#page-event-crash "Direct link to on(\"crash\")")
Added before v1.9 page.on("crash")
Emitted when the page crashes. Browser pages might crash if they try to allocate too much memory. When the page crashes, ongoing and subsequent operations will throw.
The most common way to deal with crashes is to catch an exception:
* Sync
* Async
try: # crash might happen during a click. page.click("button") # or while waiting for an event. page.wait_for_event("popup")except Error as e: pass # when the page crashes, exception message contains "crash".
try: # crash might happen during a click. await page.click("button") # or while waiting for an event. await page.wait_for_event("popup")except Error as e: pass # when the page crashes, exception message contains "crash".
**Usage**
page.on("crash", handler)
**Event data**
* [Page](/python/docs/api/class-page "Page")
* * *
### on("dialog")[](#page-event-dialog "Direct link to on(\"dialog\")")
Added before v1.9 page.on("dialog")
Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` or `beforeunload`. Listener **must** either [dialog.accept()](/python/docs/api/class-dialog#dialog-accept) or [dialog.dismiss()](/python/docs/api/class-dialog#dialog-dismiss) the dialog - otherwise the page will [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and actions like click will never finish.
**Usage**
page.on("dialog", lambda dialog: dialog.accept())
note
When no [page.on("dialog")](/python/docs/api/class-page#page-event-dialog) or [browser\_context.on("dialog")](/python/docs/api/class-browsercontext#browser-context-event-dialog) listeners are present, all dialogs are automatically dismissed.
**Event data**
* [Dialog](/python/docs/api/class-dialog "Dialog")
* * *
### on("domcontentloaded")[](#page-event-dom-content-loaded "Direct link to on(\"domcontentloaded\")")
Added in: v1.9 page.on("domcontentloaded")
Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched.
**Usage**
page.on("domcontentloaded", handler)
**Event data**
* [Page](/python/docs/api/class-page "Page")
* * *
### on("download")[](#page-event-download "Direct link to on(\"download\")")
Added before v1.9 page.on("download")
Emitted when attachment download started. User can access basic file operations on downloaded content via the passed [Download](/python/docs/api/class-download "Download") instance.
**Usage**
page.on("download", handler)
**Event data**
* [Download](/python/docs/api/class-download "Download")
* * *
### on("filechooser")[](#page-event-file-chooser "Direct link to on(\"filechooser\")")
Added in: v1.9 page.on("filechooser")
Emitted when a file chooser is supposed to appear, such as after clicking the `
`. Playwright can respond to it via setting the input files using [file\_chooser.set\_files()](/python/docs/api/class-filechooser#file-chooser-set-files) that can be uploaded after that.
page.on("filechooser", lambda file_chooser: file_chooser.set_files("/tmp/myfile.pdf"))
**Usage**
page.on("filechooser", handler)
**Event data**
* [FileChooser](/python/docs/api/class-filechooser "FileChooser")
* * *
### on("frameattached")[](#page-event-frame-attached "Direct link to on(\"frameattached\")")
Added in: v1.9 page.on("frameattached")
Emitted when a frame is attached.
**Usage**
page.on("frameattached", handler)
**Event data**
* [Frame](/python/docs/api/class-frame "Frame")
* * *
### on("framedetached")[](#page-event-frame-detached "Direct link to on(\"framedetached\")")
Added in: v1.9 page.on("framedetached")
Emitted when a frame is detached.
**Usage**
page.on("framedetached", handler)
**Event data**
* [Frame](/python/docs/api/class-frame "Frame")
* * *
### on("framenavigated")[](#page-event-frame-navigated "Direct link to on(\"framenavigated\")")
Added in: v1.9 page.on("framenavigated")
Emitted when a frame is navigated to a new url.
**Usage**
page.on("framenavigated", handler)
**Event data**
* [Frame](/python/docs/api/class-frame "Frame")
* * *
### on("load")[](#page-event-load "Direct link to on(\"load\")")
Added before v1.9 page.on("load")
Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.
**Usage**
page.on("load", handler)
**Event data**
* [Page](/python/docs/api/class-page "Page")
* * *
### on("pageerror")[](#page-event-page-error "Direct link to on(\"pageerror\")")
Added in: v1.9 page.on("pageerror")
Emitted when an uncaught exception happens within the page.
* Sync
* Async
# Log all uncaught errors to the terminalpage.on("pageerror", lambda exc: print(f"uncaught exception: {exc}"))# Navigate to a page with an exception.page.goto("data:text/html,")
# Log all uncaught errors to the terminalpage.on("pageerror", lambda exc: print(f"uncaught exception: {exc}"))# Navigate to a page with an exception.await page.goto("data:text/html,")
**Usage**
page.on("pageerror", handler)
**Event data**
* [Error](/python/docs/api/class-error "Error")
* * *
### on("popup")[](#page-event-popup "Direct link to on(\"popup\")")
Added before v1.9 page.on("popup")
Emitted when the page opens a new tab or window. This event is emitted in addition to the [browser\_context.on("page")](/python/docs/api/class-browsercontext#browser-context-event-page), but only for popups relevant to this page.
The earliest moment that page is available is when it has navigated to the initial url. For example, when opening a popup with `window.open('http://example.com')`, this event will fire when the network request to "[http://example.com](http://example.com)" is done and its response has started loading in the popup. If you would like to route/listen to this network request, use [browser\_context.route()](/python/docs/api/class-browsercontext#browser-context-route) and [browser\_context.on("request")](/python/docs/api/class-browsercontext#browser-context-event-request) respectively instead of similar methods on the [Page](/python/docs/api/class-page "Page").
* Sync
* Async
with page.expect_event("popup") as page_info: page.get_by_text("open the popup").click()popup = page_info.valueprint(popup.evaluate("location.href"))
async with page.expect_event("popup") as page_info: await page.get_by_text("open the popup").click()popup = await page_info.valueprint(await popup.evaluate("location.href"))
note
Use [page.wait\_for\_load\_state()](/python/docs/api/class-page#page-wait-for-load-state) to wait until the page gets to a particular state (you should not need it in most cases).
**Usage**
page.on("popup", handler)
**Event data**
* [Page](/python/docs/api/class-page "Page")
* * *
### on("request")[](#page-event-request "Direct link to on(\"request\")")
Added before v1.9 page.on("request")
Emitted when a page issues a request. The [request](/python/docs/api/class-request "Request") object is read-only. In order to intercept and mutate requests, see [page.route()](/python/docs/api/class-page#page-route) or [browser\_context.route()](/python/docs/api/class-browsercontext#browser-context-route).
**Usage**
page.on("request", handler)
**Event data**
* [Request](/python/docs/api/class-request "Request")
* * *
### on("requestfailed")[](#page-event-request-failed "Direct link to on(\"requestfailed\")")
Added in: v1.9 page.on("requestfailed")
Emitted when a request fails, for example by timing out.
page.on("requestfailed", lambda request: print(request.url + " " + request.failure.error_text))
note
HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with [page.on("requestfinished")](/python/docs/api/class-page#page-event-request-finished) event and not with [page.on("requestfailed")](/python/docs/api/class-page#page-event-request-failed). A request will only be considered failed when the client cannot get an HTTP response from the server, e.g. due to network error net::ERR\_FAILED.
**Usage**
page.on("requestfailed", handler)
**Event data**
* [Request](/python/docs/api/class-request "Request")
* * *
### on("requestfinished")[](#page-event-request-finished "Direct link to on(\"requestfinished\")")
Added in: v1.9 page.on("requestfinished")
Emitted when a request finishes successfully after downloading the response body. For a successful response, the sequence of events is `request`, `response` and `requestfinished`.
**Usage**
page.on("requestfinished", handler)
**Event data**
* [Request](/python/docs/api/class-request "Request")
* * *
### on("response")[](#page-event-response "Direct link to on(\"response\")")
Added before v1.9 page.on("response")
Emitted when [response](/python/docs/api/class-response "Response") status and headers are received for a request. For a successful response, the sequence of events is `request`, `response` and `requestfinished`.
**Usage**
page.on("response", handler)
**Event data**
* [Response](/python/docs/api/class-response "Response")
* * *
### on("websocket")[](#page-event-web-socket "Direct link to on(\"websocket\")")
Added in: v1.9 page.on("websocket")
Emitted when [WebSocket](/python/docs/api/class-websocket "WebSocket") request is sent.
**Usage**
page.on("websocket", handler)
**Event data**
* [WebSocket](/python/docs/api/class-websocket "WebSocket")
* * *
### on("worker")[](#page-event-worker "Direct link to on(\"worker\")")
Added before v1.9 page.on("worker")
Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) is spawned by the page.
**Usage**
page.on("worker", handler)
**Event data**
* [Worker](/python/docs/api/class-worker "Worker")
* * *
Deprecated[](#deprecated "Direct link to Deprecated")
------------------------------------------------------
### accessibility[](#page-accessibility "Direct link to accessibility")
Added before v1.9 page.accessibility
Deprecated
This property is discouraged. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with Axe.
**Usage**
page.accessibility
**Type**
* [Accessibility](/python/docs/api/class-accessibility "Accessibility")
* * *
### check[](#page-check "Direct link to check")
Added before v1.9 page.check
Discouraged
Use locator-based [locator.check()](/python/docs/api/class-locator#locator-check) instead. Read more about [locators](/python/docs/locators).
This method checks an element matching [selector](/python/docs/api/class-page#page-check-option-selector) by performing the following steps:
1. Find an element matching [selector](/python/docs/api/class-page#page-check-option-selector). If there is none, wait until a matching element is attached to the DOM.
2. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already checked, this method returns immediately.
3. Wait for [actionability](/python/docs/actionability) checks on the matched element, unless [force](/python/docs/api/class-page#page-check-option-force) option is set. If the element is detached during the checks, the whole action is retried.
4. Scroll the element into view if needed.
5. Use [page.mouse](/python/docs/api/class-page#page-mouse) to click in the center of the element.
6. Ensure that the element is now checked. If not, this method throws.
When all steps combined have not finished during the specified [timeout](/python/docs/api/class-page#page-check-option-timeout), this method throws a [TimeoutError](/python/docs/api/class-timeouterror "TimeoutError"). Passing zero timeout disables this.
**Usage**
page.check(selector)page.check(selector, **kwargs)
**Arguments**
* `selector` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-check-option-selector)
A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* `force` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-check-option-force)
Whether to bypass the [actionability](/python/docs/actionability) checks. Defaults to `false`.
* `no_wait_after` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-check-option-no-wait-after)
Deprecated
This option has no effect.
This option has no effect.
* `position` [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "Dict") _(optional)_ Added in: v1.11[#](#page-check-option-position)
* `x` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")
* `y` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")
A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.
* `strict` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_ Added in: v1.14[#](#page-check-option-strict)
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-check-option-timeout)
Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
* `trial` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_ Added in: v1.11[#](#page-check-option-trial)
When set, this method only performs the [actionability](/python/docs/actionability) checks and skips the action. Defaults to `false`. Useful to wait until the element is ready for the action without performing it.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-check-return)
* * *
### click[](#page-click "Direct link to click")
Added before v1.9 page.click
Discouraged
Use locator-based [locator.click()](/python/docs/api/class-locator#locator-click) instead. Read more about [locators](/python/docs/locators).
This method clicks an element matching [selector](/python/docs/api/class-page#page-click-option-selector) by performing the following steps:
1. Find an element matching [selector](/python/docs/api/class-page#page-click-option-selector). If there is none, wait until a matching element is attached to the DOM.
2. Wait for [actionability](/python/docs/actionability) checks on the matched element, unless [force](/python/docs/api/class-page#page-click-option-force) option is set. If the element is detached during the checks, the whole action is retried.
3. Scroll the element into view if needed.
4. Use [page.mouse](/python/docs/api/class-page#page-mouse) to click in the center of the element, or the specified [position](/python/docs/api/class-page#page-click-option-position).
5. Wait for initiated navigations to either succeed or fail, unless [no\_wait\_after](/python/docs/api/class-page#page-click-option-no-wait-after) option is set.
When all steps combined have not finished during the specified [timeout](/python/docs/api/class-page#page-click-option-timeout), this method throws a [TimeoutError](/python/docs/api/class-timeouterror "TimeoutError"). Passing zero timeout disables this.
**Usage**
page.click(selector)page.click(selector, **kwargs)
**Arguments**
* `selector` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-click-option-selector)
A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* `button` "left" | "right" | "middle" _(optional)_[#](#page-click-option-button)
Defaults to `left`.
* `click_count` [int](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "int") _(optional)_[#](#page-click-option-click-count)
defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail").
* `delay` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-click-option-delay)
Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
* `force` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-click-option-force)
Whether to bypass the [actionability](/python/docs/actionability) checks. Defaults to `false`.
* `modifiers` [List](https://docs.python.org/3/library/typing.html#typing.List "List")\["Alt" | "Control" | "ControlOrMeta" | "Meta" | "Shift"\] _(optional)_[#](#page-click-option-modifiers)
Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.
* `no_wait_after` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-click-option-no-wait-after)
Deprecated
This option will default to `true` in the future.
Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`.
* `position` [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "Dict") _(optional)_[#](#page-click-option-position)
* `x` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")
* `y` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")
A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.
* `strict` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_ Added in: v1.14[#](#page-click-option-strict)
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-click-option-timeout)
Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
* `trial` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_ Added in: v1.11[#](#page-click-option-trial)
When set, this method only performs the [actionability](/python/docs/actionability) checks and skips the action. Defaults to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys are pressed.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-click-return)
* * *
### dblclick[](#page-dblclick "Direct link to dblclick")
Added before v1.9 page.dblclick
Discouraged
Use locator-based [locator.dblclick()](/python/docs/api/class-locator#locator-dblclick) instead. Read more about [locators](/python/docs/locators).
This method double clicks an element matching [selector](/python/docs/api/class-page#page-dblclick-option-selector) by performing the following steps:
1. Find an element matching [selector](/python/docs/api/class-page#page-dblclick-option-selector). If there is none, wait until a matching element is attached to the DOM.
2. Wait for [actionability](/python/docs/actionability) checks on the matched element, unless [force](/python/docs/api/class-page#page-dblclick-option-force) option is set. If the element is detached during the checks, the whole action is retried.
3. Scroll the element into view if needed.
4. Use [page.mouse](/python/docs/api/class-page#page-mouse) to double click in the center of the element, or the specified [position](/python/docs/api/class-page#page-dblclick-option-position).
When all steps combined have not finished during the specified [timeout](/python/docs/api/class-page#page-dblclick-option-timeout), this method throws a [TimeoutError](/python/docs/api/class-timeouterror "TimeoutError"). Passing zero timeout disables this.
note
`page.dblclick()` dispatches two `click` events and a single `dblclick` event.
**Usage**
page.dblclick(selector)page.dblclick(selector, **kwargs)
**Arguments**
* `selector` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-dblclick-option-selector)
A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* `button` "left" | "right" | "middle" _(optional)_[#](#page-dblclick-option-button)
Defaults to `left`.
* `delay` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-dblclick-option-delay)
Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
* `force` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-dblclick-option-force)
Whether to bypass the [actionability](/python/docs/actionability) checks. Defaults to `false`.
* `modifiers` [List](https://docs.python.org/3/library/typing.html#typing.List "List")\["Alt" | "Control" | "ControlOrMeta" | "Meta" | "Shift"\] _(optional)_[#](#page-dblclick-option-modifiers)
Modifier keys to press. Ensures that only these modifiers are pressed during the operation, and then restores current modifiers back. If not specified, currently pressed modifiers are used. "ControlOrMeta" resolves to "Control" on Windows and Linux and to "Meta" on macOS.
* `no_wait_after` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-dblclick-option-no-wait-after)
Deprecated
This option has no effect.
This option has no effect.
* `position` [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "Dict") _(optional)_[#](#page-dblclick-option-position)
* `x` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")
* `y` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float")
A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.
* `strict` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_ Added in: v1.14[#](#page-dblclick-option-strict)
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-dblclick-option-timeout)
Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
* `trial` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_ Added in: v1.11[#](#page-dblclick-option-trial)
When set, this method only performs the [actionability](/python/docs/actionability) checks and skips the action. Defaults to `false`. Useful to wait until the element is ready for the action without performing it. Note that keyboard `modifiers` will be pressed regardless of `trial` to allow testing elements which are only visible when those keys are pressed.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-dblclick-return)
* * *
### dispatch\_event[](#page-dispatch-event "Direct link to dispatch_event")
Added before v1.9 page.dispatch\_event
Discouraged
Use locator-based [locator.dispatch\_event()](/python/docs/api/class-locator#locator-dispatch-event) instead. Read more about [locators](/python/docs/locators).
The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element, `click` is dispatched. This is equivalent to calling [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
**Usage**
* Sync
* Async
page.dispatch_event("button#submit", "click")
await page.dispatch_event("button#submit", "click")
Under the hood, it creates an instance of an event based on the given [type](/python/docs/api/class-page#page-dispatch-event-option-type), initializes it with [event\_init](/python/docs/api/class-page#page-dispatch-event-option-event-init) properties and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
Since [event\_init](/python/docs/api/class-page#page-dispatch-event-option-event-init) is event-specific, please refer to the events documentation for the lists of initial properties:
* [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
* [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
* [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
* [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
* [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
* [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
* [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
* [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
* [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
* [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)
You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
* Sync
* Async
# note you can only create data_transfer in chromium and firefoxdata_transfer = page.evaluate_handle("new DataTransfer()")page.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
# note you can only create data_transfer in chromium and firefoxdata_transfer = await page.evaluate_handle("new DataTransfer()")await page.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
**Arguments**
* `selector` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-dispatch-event-option-selector)
A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used.
* `type` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-dispatch-event-option-type)
DOM event type: `"click"`, `"dragstart"`, etc.
* `event_init` [EvaluationArgument](/python/docs/evaluating#evaluation-argument "EvaluationArgument") _(optional)_[#](#page-dispatch-event-option-event-init)
Optional event-specific initialization properties.
* `strict` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_ Added in: v1.14[#](#page-dispatch-event-option-strict)
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-dispatch-event-option-timeout)
Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
**Returns**
* [NoneType](https://docs.python.org/3/library/constants.html#None "None")[#](#page-dispatch-event-return)
* * *
### eval\_on\_selector[](#page-eval-on-selector "Direct link to eval_on_selector")
Added in: v1.9 page.eval\_on\_selector
Discouraged
This method does not wait for the element to pass actionability checks and therefore can lead to the flaky tests. Use [locator.evaluate()](/python/docs/api/class-locator#locator-evaluate), other [Locator](/python/docs/api/class-locator "Locator") helper methods or web-first assertions instead.
The method finds an element matching the specified selector within the page and passes it as a first argument to [expression](/python/docs/api/class-page#page-eval-on-selector-option-expression). If no elements match the selector, the method throws an error. Returns the value of [expression](/python/docs/api/class-page#page-eval-on-selector-option-expression).
If [expression](/python/docs/api/class-page#page-eval-on-selector-option-expression) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then [page.eval\_on\_selector()](/python/docs/api/class-page#page-eval-on-selector) would wait for the promise to resolve and return its value.
**Usage**
* Sync
* Async
search_value = page.eval_on_selector("#search", "el => el.value")preload_href = page.eval_on_selector("link[rel=preload]", "el => el.href")html = page.eval_on_selector(".main-container", "(e, suffix) => e.outer_html + suffix", "hello")
search_value = await page.eval_on_selector("#search", "el => el.value")preload_href = await page.eval_on_selector("link[rel=preload]", "el => el.href")html = await page.eval_on_selector(".main-container", "(e, suffix) => e.outer_html + suffix", "hello")
**Arguments**
* `selector` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-eval-on-selector-option-selector)
A selector to query for.
* `expression` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-eval-on-selector-option-expression)
JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.
* `arg` [EvaluationArgument](/python/docs/evaluating#evaluation-argument "EvaluationArgument") _(optional)_[#](#page-eval-on-selector-option-arg)
Optional argument to pass to [expression](/python/docs/api/class-page#page-eval-on-selector-option-expression).
* `strict` [bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_ Added in: v1.14[#](#page-eval-on-selector-option-strict)
When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.
**Returns**
* [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "Dict")[#](#page-eval-on-selector-return)
* * *
### eval\_on\_selector\_all[](#page-eval-on-selector-all "Direct link to eval_on_selector_all")
Added in: v1.9 page.eval\_on\_selector\_all
Discouraged
In most cases, [locator.evaluate\_all()](/python/docs/api/class-locator#locator-evaluate-all), other [Locator](/python/docs/api/class-locator "Locator") helper methods and web-first assertions do a better job.
The method finds all elements matching the specified selector within the page and passes an array of matched elements as a first argument to [expression](/python/docs/api/class-page#page-eval-on-selector-all-option-expression). Returns the result of [expression](/python/docs/api/class-page#page-eval-on-selector-all-option-expression) invocation.
If [expression](/python/docs/api/class-page#page-eval-on-selector-all-option-expression) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"), then [page.eval\_on\_selector\_all()](/python/docs/api/class-page#page-eval-on-selector-all) would wait for the promise to resolve and return its value.
**Usage**
* Sync
* Async
div_counts = page.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
div_counts = await page.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
**Arguments**
* `selector` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-eval-on-selector-all-option-selector)
A selector to query for.
* `expression` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str")[#](#page-eval-on-selector-all-option-expression)
JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.
* `arg` [EvaluationArgument](/python/docs/evaluating#evaluation-argument "EvaluationArgument") _(optional)_[#](#page-eval-on-selector-all-option-arg)
Optional argument to pass to [expression](/python/docs/api/class-page#page-eval-on-selector-all-option-expression).
**Returns**
* [Dict](https://docs.python.org/3/library/typing.html#typing.Dict "Dict")[#](#page-eval-on-selector-all-return)
* * *
### expect\_navigation[](#page-wait-for-navigation "Direct link to expect_navigation")
Added before v1.9 page.expect\_navigation
Deprecated
This method is inherently racy, please use [page.wait\_for\_url()](/python/docs/api/class-page#page-wait-for-url) instead.
Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with `null`.
**Usage**
This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectly cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`. Consider this example:
* Sync
* Async
with page.expect_navigation(): # This action triggers the navigation after a timeout. page.get_by_text("Navigate after timeout").click()# Resolves after navigation has finished
async with page.expect_navigation(): # This action triggers the navigation after a timeout. await page.get_by_text("Navigate after timeout").click()# Resolves after navigation has finished
note
Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is considered a navigation.
**Arguments**
* `timeout` [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float") _(optional)_[#](#page-wait-for-navigation-option-timeout)
Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [browser\_context.set\_default\_navigation\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-navigation-timeout), [browser\_context.set\_default\_timeout()](/python/docs/api/class-browsercontext#browser-context-set-default-timeout), [page.set\_default\_navigation\_timeout()](/python/docs/api/class-page#page-set-default-navigation-timeout) or [page.set\_default\_timeout()](/python/docs/api/class-page#page-set-default-timeout) methods.
* `url` [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str") | [Pattern](https://docs.python.org/3/library/re.html "Pattern") | [Callable](https://docs.python.org/3/library/typing.html#typing.Callable "Callable")\[[URL](https://en.wikipedia.org/wiki/URL "URL")\]:[bool](https://docs.python.org/3/library/stdtypes.html "bool") _(optional)_[#](#page-wait-for-navigation-option-url)
A glob pattern, regex pattern or predicate receiving [URL](https://en.wikipedia.org/wiki/URL "URL") to match while waiting for the navigation. Note that if the parameter is a string without wildcard characters, the method will wait for navigation to URL that is exactly equal to the string.
* `wait_until` "load" | "domcontentloaded" | "networkidle" | "commit" _(optional)_[#](#page-wait-for-navigation-option-wait-until)
When to consider operation succeeded, defaults to `load`. Events can be either:
* `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired.
* `'load'` - consider operation to be finished when the `load` event is fired.
* `'networkidle'` - **DISCOURAGED** consider operation to be finished when there are no network connections for at least `500` ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
* `'commit'` - consider operation to be finished when network response is received and the document started loading.
**Returns**
* [EventContextManager](https://docs.python.org/3/reference/datamodel.html#context-managers "Event context manager")\[[Response](/python/docs/api/class-response "Response")\][#](#page-wait-for-navigation-return)
* * *
### fill[](#page-fill "Direct link to fill")
Added before v1.9 page.fill
Discouraged
Use locator-based [locator.fill()](/python/docs/api/class-locator#locator-fill) instead. Read more about [locators](/python/docs/locators).
This method waits for an element matching [selector](/python/docs/api/class-page#page-fill-option-selector), waits for [actionability](/python/docs/actionability) checks, focuses the element, fills it and triggers an `input` event after filling. Note that you can pass an empty string to clear the input field.
If the target element is not an `
`, `