# THIS DOCUMENT CONTAINS THE COMPLETE DOCUMENTATION FOR PLAYWRIGHT PYTHON. # Getting started - Library Getting started - Library ========================= Installation[​](#installation "Direct link to Installation") ------------------------------------------------------------ ### Pip[​](#pip "Direct link to Pip") [![PyPI version](https://badge.fury.io/py/playwright.svg)](https://pypi.python.org/pypi/playwright/) pip install --upgrade pippip install playwrightplaywright install ### Conda[​](#conda "Direct link to Conda") [![Anaconda version](https://img.shields.io/conda/v/microsoft/playwright)](https://anaconda.org/Microsoft/playwright) conda config --add channels conda-forgeconda config --add channels microsoftconda install playwrightplaywright install These commands download the Playwright package and install browser binaries for Chromium, Firefox and WebKit. To modify this behavior see [installation parameters](/python/docs/browsers#install-browsers). Usage[​](#usage "Direct link to Usage") --------------------------------------- Once installed, you can `import` Playwright in a Python script, and launch any of the 3 browsers (`chromium`, `firefox` and `webkit`). from playwright.sync_api import sync_playwrightwith sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() page.goto("https://playwright.dev") print(page.title()) browser.close() Playwright supports two variations of the API: synchronous and asynchronous. If your modern project uses [asyncio](https://docs.python.org/3/library/asyncio.html), you should use async API: import asynciofrom playwright.async_api import async_playwrightasync def main(): async with async_playwright() as p: browser = await p.chromium.launch() page = await browser.new_page() await page.goto("https://playwright.dev") print(await page.title()) await browser.close()asyncio.run(main()) First script[​](#first-script "Direct link to First script") ------------------------------------------------------------ In our first script, we will navigate to `https://playwright.dev/` and take a screenshot in WebKit. from playwright.sync_api import sync_playwrightwith sync_playwright() as p: browser = p.webkit.launch() page = browser.new_page() page.goto("https://playwright.dev/") page.screenshot(path="example.png") browser.close() By default, Playwright runs the browsers in headless mode. To see the browser UI, set [headless](/python/docs/api/class-browsertype#browser-type-launch-option-headless) option to `False`. You can also use [slow\_mo](/python/docs/api/class-browsertype#browser-type-launch-option-slow-mo) to slow down execution. Learn more in the debugging tools [section](/python/docs/debug). firefox.launch(headless=False, slow_mo=50) Interactive mode (REPL)[​](#interactive-mode-repl "Direct link to Interactive mode (REPL)") ------------------------------------------------------------------------------------------- You can launch the interactive python REPL: python and then launch Playwright within it for quick experimentation: from playwright.sync_api import sync_playwrightplaywright = sync_playwright().start()# Use playwright.chromium, playwright.firefox or playwright.webkit# Pass headless=False to launch() to see the browser UIbrowser = playwright.chromium.launch()page = browser.new_page()page.goto("https://playwright.dev/")page.screenshot(path="example.png")browser.close()playwright.stop() Async REPL such as `asyncio` REPL: python -m asyncio from playwright.async_api import async_playwrightplaywright = await async_playwright().start()browser = await playwright.chromium.launch()page = await browser.new_page()await page.goto("https://playwright.dev/")await page.screenshot(path="example.png")await browser.close()await playwright.stop() Pyinstaller[​](#pyinstaller "Direct link to Pyinstaller") --------------------------------------------------------- You can use Playwright with [Pyinstaller](https://www.pyinstaller.org/) to create standalone executables. main.py from playwright.sync_api import sync_playwrightwith sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() page.goto("https://playwright.dev/") page.screenshot(path="example.png") browser.close() If you want to bundle browsers with the executables: * Bash * PowerShell * Batch PLAYWRIGHT_BROWSERS_PATH=0 playwright install chromiumpyinstaller -F main.py $env:PLAYWRIGHT_BROWSERS_PATH="0"playwright install chromiumpyinstaller -F main.py set PLAYWRIGHT_BROWSERS_PATH=0playwright install chromiumpyinstaller -F main.py note Bundling the browsers with the executables will generate bigger binaries. It is recommended to only bundle the browsers you use. Known issues[​](#known-issues "Direct link to Known issues") ------------------------------------------------------------ ### `time.sleep()` leads to outdated state[​](#timesleep-leads-to-outdated-state "Direct link to timesleep-leads-to-outdated-state") Most likely you don't need to wait manually, since Playwright has [auto-waiting](/python/docs/actionability). If you still rely on it, you should use `page.wait_for_timeout(5000)` instead of `time.sleep(5)` and it is better to not wait for a timeout at all, but sometimes it is useful for debugging. In these cases, use our wait (`wait_for_timeout`) method instead of the `time` module. This is because we internally rely on asynchronous operations and when using `time.sleep(5)` they can't get processed correctly. ### incompatible with `SelectorEventLoop` of `asyncio` on Windows[​](#incompatible-with-selectoreventloop-of-asyncio-on-windows "Direct link to incompatible-with-selectoreventloop-of-asyncio-on-windows") Playwright runs the driver in a subprocess, so it requires `ProactorEventLoop` of `asyncio` on Windows because `SelectorEventLoop` does not supports async subprocesses. On Windows Python 3.7, Playwright sets the default event loop to `ProactorEventLoop` as it is default on Python 3.8+. ### Threading[​](#threading "Direct link to Threading") Playwright's API is not thread-safe. If you are using Playwright in a multi-threaded environment, you should create a playwright instance per thread. See [threading issue](https://github.com/microsoft/playwright-python/issues/623) for more details. # Release notes Release notes ============= Version 1.55[​](#version-155 "Direct link to Version 1.55") ----------------------------------------------------------- ### Codegen[​](#codegen "Direct link to Codegen") * Automatic `to_be_visible()` assertions: Codegen can now generate automatic `to_be_visible()` assertions for common UI interactions. This feature can be enabled in the Codegen settings UI. ### Breaking Changes[​](#breaking-changes "Direct link to Breaking Changes") * ⚠️ Dropped support for Chromium extension manifest v2. ### Miscellaneous[​](#miscellaneous "Direct link to Miscellaneous") * Added support for Debian 13 "Trixie". ### Browser Versions[​](#browser-versions "Direct link to Browser Versions") * Chromium 140.0.7339.16 * Mozilla Firefox 141.0 * WebKit 26.0 This version was also tested against the following stable channels: * Google Chrome 139 * Microsoft Edge 139 Version 1.54[​](#version-154 "Direct link to Version 1.54") ----------------------------------------------------------- ### Highlights[​](#highlights "Direct link to Highlights") * New cookie property `partition_key` in [browser\_context.cookies()](/python/docs/api/class-browsercontext#browser-context-cookies) and [browser\_context.add\_cookies()](/python/docs/api/class-browsercontext#browser-context-add-cookies). This property allows to save and restore partitioned cookies. See [CHIPS MDN article](https://developer.mozilla.org/en-US/docs/Web/Privacy/Guides/Privacy_sandbox/Partitioned_cookies) for more information. Note that browsers have different support and defaults for cookie partitioning. * New option `--user-data-dir` in multiple commands. You can specify the same user data dir to reuse browsing state, like authentication, between sessions. playwright codegen --user-data-dir=./user-data * `playwright open` does not open the test recorder anymore. Use `playwright codegen` instead. ### Browser Versions[​](#browser-versions-1 "Direct link to Browser Versions") * Chromium 139.0.7258.5 * Mozilla Firefox 140.0.2 * WebKit 26.0 This version was also tested against the following stable channels: * Google Chrome 140 * Microsoft Edge 140 Version 1.53[​](#version-153 "Direct link to Version 1.53") ----------------------------------------------------------- ### Trace Viewer and HTML Reporter Updates[​](#trace-viewer-and-html-reporter-updates "Direct link to Trace Viewer and HTML Reporter Updates") * New Steps in Trace Viewer: ![New Trace Viewer Steps](https://github.com/user-attachments/assets/1963ff7d-4070-41be-a79b-4333176921a2) * New method [locator.describe()](/python/docs/api/class-locator#locator-describe) to describe a locator. Used for trace viewer. button = page.get_by_test_id("btn-sub").describe("Subscribe button")button.click() * `python -m playwright install --list` will now list all installed browsers, versions and locations. ### Browser Versions[​](#browser-versions-2 "Direct link to Browser Versions") * Chromium 138.0.7204.4 * Mozilla Firefox 139.0 * WebKit 18.5 This version was also tested against the following stable channels: * Google Chrome 137 * Microsoft Edge 137 Version 1.52[​](#version-152 "Direct link to Version 1.52") ----------------------------------------------------------- ### Highlights[​](#highlights-1 "Direct link to Highlights") * New method [expect(locator).to\_contain\_class()](/python/docs/api/class-locatorassertions#locator-assertions-to-contain-class) to ergonomically assert individual class names on the element. expect(page.get_by_role('listitem', name='Ship v1.52')).to_contain_class('done') * [Aria Snapshots](/python/docs/aria-snapshots) got two new properties: [`/children`](/python/docs/aria-snapshots#strict-matching) for strict matching and `/url` for links. expect(locator).to_match_aria_snapshot(""" - list - /children: equal - listitem: Feature A - listitem: - link "Feature B": - /url: "https://playwright.dev"""") ### Miscellaneous[​](#miscellaneous-1 "Direct link to Miscellaneous") * New option [max\_redirects](/python/docs/api/class-apirequest#api-request-new-context-option-max-redirects) in [api\_request.new\_context()](/python/docs/api/class-apirequest#api-request-new-context) to control the maximum number of redirects. ### Breaking Changes[​](#breaking-changes-1 "Direct link to Breaking Changes") * Glob URL patterns in methods like [page.route()](/python/docs/api/class-page#page-route) do not support `?` and `[]` anymore. We recommend using regular expressions instead. * Method [route.continue\_()](/python/docs/api/class-route#route-continue) does not allow to override the `Cookie` header anymore. If a `Cookie` header is provided, it will be ignored, and the cookie will be loaded from the browser's cookie store. To set custom cookies, use [browser\_context.add\_cookies()](/python/docs/api/class-browsercontext#browser-context-add-cookies). * macOS 13 is now deprecated and will no longer receive WebKit updates. Please upgrade to a more recent macOS version to continue benefiting from the latest WebKit improvements. ### Browser Versions[​](#browser-versions-3 "Direct link to Browser Versions") * Chromium 136.0.7103.25 * Mozilla Firefox 137.0 * WebKit 18.4 This version was also tested against the following stable channels: * Google Chrome 135 * Microsoft Edge 135 Version 1.51[​](#version-151 "Direct link to Version 1.51") ----------------------------------------------------------- ### Highlights[​](#highlights-2 "Direct link to Highlights") * New option [indexed\_db](/python/docs/api/class-browsercontext#browser-context-storage-state-option-indexed-db) for [browser\_context.storage\_state()](/python/docs/api/class-browsercontext#browser-context-storage-state) allows to save and restore IndexedDB contents. Useful when your application uses [IndexedDB API](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) to store authentication tokens, like Firebase Authentication. Here is an example following the [authentication guide](/python/docs/auth#reusing-signed-in-state): # Save storage state into the file. Make sure to include IndexedDB.storage = await context.storage_state(path="state.json", indexed_db=True)# Create a new context with the saved storage state.context = await browser.new_context(storage_state="state.json") * New option [visible](/python/docs/api/class-locator#locator-filter-option-visible) for [locator.filter()](/python/docs/api/class-locator#locator-filter) allows matching only visible elements. # Ignore invisible todo items.todo_items = page.get_by_test_id("todo-item").filter(visible=True)# Check there are exactly 3 visible ones.await expect(todo_items).to_have_count(3) * New option `contrast` for methods [page.emulate\_media()](/python/docs/api/class-page#page-emulate-media) and [browser.new\_context()](/python/docs/api/class-browser#browser-new-context) allows to emulate the `prefers-contrast` media feature. * New option [fail\_on\_status\_code](/python/docs/api/class-apirequest#api-request-new-context-option-fail-on-status-code) makes all fetch requests made through the [APIRequestContext](/python/docs/api/class-apirequestcontext "APIRequestContext") throw on response codes other than 2xx and 3xx. ### Browser Versions[​](#browser-versions-4 "Direct link to Browser Versions") * Chromium 134.0.6998.35 * Mozilla Firefox 135.0 * WebKit 18.4 This version was also tested against the following stable channels: * Google Chrome 133 * Microsoft Edge 133 Version 1.50[​](#version-150 "Direct link to Version 1.50") ----------------------------------------------------------- ### Async Pytest Plugin[​](#async-pytest-plugin "Direct link to Async Pytest Plugin") * [Playwright's Pytest plugin](/python/docs/test-runners) now has support for [Async Fixtures](https://playwright.dev/python/docs/test-runners#async-fixtures). ### Miscellaneous[​](#miscellaneous-2 "Direct link to Miscellaneous") * Added method [expect(locator).to\_have\_accessible\_error\_message()](/python/docs/api/class-locatorassertions#locator-assertions-to-have-accessible-error-message) to assert the Locator points to an element with a given [aria errormessage](https://w3c.github.io/aria/#aria-errormessage). ### UI updates[​](#ui-updates "Direct link to UI updates") * New button in Codegen for picking elements to produce aria snapshots. * Additional details (such as keys pressed) are now displayed alongside action API calls in traces. * Display of `canvas` content in traces is error-prone. Display is now disabled by default, and can be enabled via the `Display canvas content` UI setting. * `Call` and `Network` panels now display additional time information. ### Breaking[​](#breaking "Direct link to Breaking") * [expect(locator).to\_be\_editable()](/python/docs/api/class-locatorassertions#locator-assertions-to-be-editable) and [locator.is\_editable()](/python/docs/api/class-locator#locator-is-editable) now throw if the target element is not ``, `` elements. page.get_by_label("Upload directory").set_input_files('mydir') * Multiple methods like [locator.click()](/python/docs/api/class-locator#locator-click) or [locator.press()](/python/docs/api/class-locator#locator-press) now support a `ControlOrMeta` modifier key. This key maps to `Meta` on macOS and maps to `Control` on Windows and Linux. # Press the common keyboard shortcut Control+S or Meta+S to trigger a "Save" operation.page.keyboard.press("ControlOrMeta+S") * New property `httpCredentials.send` in [api\_request.new\_context()](/python/docs/api/class-apirequest#api-request-new-context) that allows to either always send the `Authorization` header or only send it in response to `401 Unauthorized`. * Playwright now supports Chromium, Firefox and WebKit on Ubuntu 24.04. * v1.45 is the last release to receive WebKit update for macOS 12 Monterey. Please update macOS to keep using the latest WebKit. ### Browser Versions[​](#browser-versions-10 "Direct link to Browser Versions") * Chromium 127.0.6533.5 * Mozilla Firefox 127.0 * WebKit 17.4 This version was also tested against the following stable channels: * Google Chrome 126 * Microsoft Edge 126 Version 1.44[​](#version-144 "Direct link to Version 1.44") ----------------------------------------------------------- ### New APIs[​](#new-apis "Direct link to New APIs") **Accessibility assertions** * [expect(locator).to\_have\_accessible\_name()](/python/docs/api/class-locatorassertions#locator-assertions-to-have-accessible-name) checks if the element has the specified accessible name: locator = page.get_by_role("button")expect(locator).to_have_accessible_name("Submit") * [expect(locator).to\_have\_accessible\_description()](/python/docs/api/class-locatorassertions#locator-assertions-to-have-accessible-description) checks if the element has the specified accessible description: locator = page.get_by_role("button")expect(locator).to_have_accessible_description("Upload a photo") * [expect(locator).to\_have\_role()](/python/docs/api/class-locatorassertions#locator-assertions-to-have-role) checks if the element has the specified ARIA role: locator = page.get_by_test_id("save-button")expect(locator).to_have_role("button") **Locator handler** * After executing the handler added with [page.add\_locator\_handler()](/python/docs/api/class-page#page-add-locator-handler), Playwright will now wait until the overlay that triggered the handler is not visible anymore. You can opt-out of this behavior with the new `no_wait_after` option. * You can use new `times` option in [page.add\_locator\_handler()](/python/docs/api/class-page#page-add-locator-handler) to specify maximum number of times the handler should be run. * The handler in [page.add\_locator\_handler()](/python/docs/api/class-page#page-add-locator-handler) now accepts the locator as argument. * New [page.remove\_locator\_handler()](/python/docs/api/class-page#page-remove-locator-handler) method for removing previously added locator handlers. locator = page.get_by_text("This interstitial covers the button")page.add_locator_handler(locator, lambda overlay: overlay.locator("#close").click(), times=3, no_wait_after=True)# Run your tests that can be interrupted by the overlay.# ...page.remove_locator_handler(locator) **Miscellaneous options** * [expect(page).to\_have\_url()](/python/docs/api/class-pageassertions#page-assertions-to-have-url) now supports `ignore_case` [option](/python/docs/api/class-pageassertions#page-assertions-to-have-url-option-ignore-case). ### Browser Versions[​](#browser-versions-11 "Direct link to Browser Versions") * Chromium 125.0.6422.14 * Mozilla Firefox 125.0.1 * WebKit 17.4 This version was also tested against the following stable channels: * Google Chrome 124 * Microsoft Edge 124 Version 1.43[​](#version-143 "Direct link to Version 1.43") ----------------------------------------------------------- ### New APIs[​](#new-apis-1 "Direct link to New APIs") * Method [browser\_context.clear\_cookies()](/python/docs/api/class-browsercontext#browser-context-clear-cookies) now supports filters to remove only some cookies. # Clear all cookies.context.clear_cookies()# New: clear cookies with a particular name.context.clear_cookies(name="session-id")# New: clear cookies for a particular domain.context.clear_cookies(domain="my-origin.com") * New method [locator.content\_frame](/python/docs/api/class-locator#locator-content-frame) converts a [Locator](/python/docs/api/class-locator "Locator") object to a [FrameLocator](/python/docs/api/class-framelocator "FrameLocator"). This can be useful when you have a [Locator](/python/docs/api/class-locator "Locator") object obtained somewhere, and later on would like to interact with the content inside the frame. locator = page.locator("iframe[name='embedded']")# ...frame_locator = locator.content_frameframe_locator.getByRole("button").click() * New method [frame\_locator.owner](/python/docs/api/class-framelocator#frame-locator-owner) converts a [FrameLocator](/python/docs/api/class-framelocator "FrameLocator") object to a [Locator](/python/docs/api/class-locator "Locator"). This can be useful when you have a [FrameLocator](/python/docs/api/class-framelocator "FrameLocator") object obtained somewhere, and later on would like to interact with the `iframe` element. frame_locator = page.frame_locator("iframe[name='embedded']")# ...locator = frame_locator.ownerexpect(locator).to_be_visible() * Conda builds are now published for macOS-arm64 and Linux-arm64. ### Browser Versions[​](#browser-versions-12 "Direct link to Browser Versions") * Chromium 124.0.6367.8 * Mozilla Firefox 124.0 * WebKit 17.4 This version was also tested against the following stable channels: * Google Chrome 123 * Microsoft Edge 123 Version 1.42[​](#version-142 "Direct link to Version 1.42") ----------------------------------------------------------- ### New Locator Handler[​](#new-locator-handler "Direct link to New Locator Handler") New method [page.add\_locator\_handler()](/python/docs/api/class-page#page-add-locator-handler) registers a callback that will be invoked when specified element becomes visible and may block Playwright actions. The callback can get rid of the overlay. Here is an example that closes a cookie dialog when it appears. # Setup the handler.page.add_locator_handler( page.get_by_role("heading", name="Hej! You are in control of your cookies."), lambda: page.get_by_role("button", name="Accept all").click(),)# Write the test as usual.page.goto("https://www.ikea.com/")page.get_by_role("link", name="Collection of blue and white").click()expect(page.get_by_role("heading", name="Light and easy")).to_be_visible() ### New APIs[​](#new-apis-2 "Direct link to New APIs") * [page.pdf()](/python/docs/api/class-page#page-pdf) accepts two new options [tagged](/python/docs/api/class-page#page-pdf-option-tagged) and [outline](/python/docs/api/class-page#page-pdf-option-outline). ### Announcements[​](#announcements "Direct link to Announcements") * ⚠️ Ubuntu 18 is not supported anymore. ### Browser Versions[​](#browser-versions-13 "Direct link to Browser Versions") * Chromium 123.0.6312.4 * Mozilla Firefox 123.0 * WebKit 17.4 This version was also tested against the following stable channels: * Google Chrome 122 * Microsoft Edge 123 Version 1.41[​](#version-141 "Direct link to Version 1.41") ----------------------------------------------------------- ### New APIs[​](#new-apis-3 "Direct link to New APIs") * New method [page.unroute\_all()](/python/docs/api/class-page#page-unroute-all) removes all routes registered by [page.route()](/python/docs/api/class-page#page-route) and [page.route\_from\_har()](/python/docs/api/class-page#page-route-from-har). Optionally allows to wait for ongoing routes to finish, or ignore any errors from them. * New method [browser\_context.unroute\_all()](/python/docs/api/class-browsercontext#browser-context-unroute-all) removes all routes registered by [browser\_context.route()](/python/docs/api/class-browsercontext#browser-context-route) and [browser\_context.route\_from\_har()](/python/docs/api/class-browsercontext#browser-context-route-from-har). Optionally allows to wait for ongoing routes to finish, or ignore any errors from them. * New options [style](/python/docs/api/class-page#page-screenshot-option-style) in [page.screenshot()](/python/docs/api/class-page#page-screenshot) and [style](/python/docs/api/class-locator#locator-screenshot-option-style) in [locator.screenshot()](/python/docs/api/class-locator#locator-screenshot) to add custom CSS to the page before taking a screenshot. ### Browser Versions[​](#browser-versions-14 "Direct link to Browser Versions") * Chromium 121.0.6167.57 * Mozilla Firefox 121.0 * WebKit 17.4 This version was also tested against the following stable channels: * Google Chrome 120 * Microsoft Edge 120 Version 1.40[​](#version-140 "Direct link to Version 1.40") ----------------------------------------------------------- ### Test Generator Update[​](#test-generator-update "Direct link to Test Generator Update") ![Playwright Test Generator](https://github.com/microsoft/playwright/assets/9881434/e8d67e2e-f36d-4301-8631-023948d3e190) New tools to generate assertions: * "Assert visibility" tool generates [expect(locator).to\_be\_visible()](/python/docs/api/class-locatorassertions#locator-assertions-to-be-visible). * "Assert value" tool generates [expect(locator).to\_have\_value()](/python/docs/api/class-locatorassertions#locator-assertions-to-have-value). * "Assert text" tool generates [expect(locator).to\_contain\_text()](/python/docs/api/class-locatorassertions#locator-assertions-to-contain-text). Here is an example of a generated test with assertions: from playwright.sync_api import Page, expectdef test_example(page: Page) -> None: page.goto("https://playwright.dev/") page.get_by_role("link", name="Get started").click() expect(page.get_by_label("Breadcrumbs").get_by_role("list")).to_contain_text("Installation") expect(page.get_by_label("Search")).to_be_visible() page.get_by_label("Search").click() page.get_by_placeholder("Search docs").fill("locator") expect(page.get_by_placeholder("Search docs")).to_have_value("locator"); ### New APIs[​](#new-apis-4 "Direct link to New APIs") * Options [reason](/python/docs/api/class-page#page-close-option-reason) in [page.close()](/python/docs/api/class-page#page-close), [reason](/python/docs/api/class-browsercontext#browser-context-close-option-reason) in [browser\_context.close()](/python/docs/api/class-browsercontext#browser-context-close) and [reason](/python/docs/api/class-browser#browser-close-option-reason) in [browser.close()](/python/docs/api/class-browser#browser-close). Close reason is reported for all operations interrupted by the closure. * Option [firefox\_user\_prefs](/python/docs/api/class-browsertype#browser-type-launch-persistent-context-option-firefox-user-prefs) in [browser\_type.launch\_persistent\_context()](/python/docs/api/class-browsertype#browser-type-launch-persistent-context). ### Other Changes[​](#other-changes "Direct link to Other Changes") * Method [download.path()](/python/docs/api/class-download#download-path) throws an error for failed and cancelled downloads. ### Browser Versions[​](#browser-versions-15 "Direct link to Browser Versions") * Chromium 120.0.6099.28 * Mozilla Firefox 119.0 * WebKit 17.4 This version was also tested against the following stable channels: * Google Chrome 119 * Microsoft Edge 119 Version 1.39[​](#version-139 "Direct link to Version 1.39") ----------------------------------------------------------- Evergreen browsers update. ### Browser Versions[​](#browser-versions-16 "Direct link to Browser Versions") * Chromium 119.0.6045.9 * Mozilla Firefox 118.0.1 * WebKit 17.4 This version was also tested against the following stable channels: * Google Chrome 118 * Microsoft Edge 118 Version 1.38[​](#version-138 "Direct link to Version 1.38") ----------------------------------------------------------- ### Trace Viewer Updates[​](#trace-viewer-updates-1 "Direct link to Trace Viewer Updates") ![Playwright Trace Viewer](https://github.com/microsoft/playwright/assets/746130/0c41e20d-c54b-4600-8ca8-1cbb6393ddef) 1. Zoom into time range. 2. Network panel redesign. ### New APIs[​](#new-apis-5 "Direct link to New APIs") * [browser\_context.on("weberror")](/python/docs/api/class-browsercontext#browser-context-event-web-error) * [locator.press\_sequentially()](/python/docs/api/class-locator#locator-press-sequentially) ### Deprecations[​](#deprecations "Direct link to Deprecations") * The following methods were deprecated: [page.type()](/python/docs/api/class-page#page-type), [frame.type()](/python/docs/api/class-frame#frame-type), [locator.type()](/python/docs/api/class-locator#locator-type) and [element\_handle.type()](/python/docs/api/class-elementhandle#element-handle-type). Please use [locator.fill()](/python/docs/api/class-locator#locator-fill) instead which is much faster. Use [locator.press\_sequentially()](/python/docs/api/class-locator#locator-press-sequentially) only if there is a special keyboard handling on the page, and you need to press keys one-by-one. ### Browser Versions[​](#browser-versions-17 "Direct link to Browser Versions") * Chromium 117.0.5938.62 * Mozilla Firefox 117.0 * WebKit 17.0 This version was also tested against the following stable channels: * Google Chrome 116 * Microsoft Edge 116 Version 1.37[​](#version-137 "Direct link to Version 1.37") ----------------------------------------------------------- ### Highlights[​](#highlights-3 "Direct link to Highlights") * New [\--full-page-screenshot](/python/docs/test-runners#cli-arguments) command line flag allows taking a full page screenshot on failure. * It is now possible to override the context options for a single test by using the [browser\_context\_args](/python/docs/test-runners#fixtures) marker. * `pytest-playwright` is now also getting published [on Anaconda](https://anaconda.org/Microsoft/pytest-playwright/) ### 📚 Debian 12 Bookworm Support[​](#-debian-12-bookworm-support "Direct link to 📚 Debian 12 Bookworm Support") Playwright now supports Debian 12 Bookworm on both x86\_64 and arm64 for Chromium, Firefox and WebKit. Let us know if you encounter any issues! Linux support looks like this: Ubuntu 20.04 Ubuntu 22.04 Debian 11 Debian 12 Chromium ✅ ✅ ✅ ✅ WebKit ✅ ✅ ✅ ✅ Firefox ✅ ✅ ✅ ✅ ### Browser Versions[​](#browser-versions-18 "Direct link to Browser Versions") * Chromium 116.0.5845.82 * Mozilla Firefox 115.0 * WebKit 17.0 This version was also tested against the following stable channels: * Google Chrome 115 * Microsoft Edge 115 Version 1.36[​](#version-136 "Direct link to Version 1.36") ----------------------------------------------------------- 🏝️ Summer maintenance release. ### Browser Versions[​](#browser-versions-19 "Direct link to Browser Versions") * Chromium 115.0.5790.75 * Mozilla Firefox 115.0 * WebKit 17.0 This version was also tested against the following stable channels: * Google Chrome 114 * Microsoft Edge 114 Version 1.35[​](#version-135 "Direct link to Version 1.35") ----------------------------------------------------------- ### Highlights[​](#highlights-4 "Direct link to Highlights") * New option `mask_color` for methods [page.screenshot()](/python/docs/api/class-page#page-screenshot) and [locator.screenshot()](/python/docs/api/class-locator#locator-screenshot) to change default masking color. * New `uninstall` CLI command to uninstall browser binaries: $ playwright uninstall # remove browsers installed by this installation$ playwright uninstall --all # remove all ever-install Playwright browsers ### Browser Versions[​](#browser-versions-20 "Direct link to Browser Versions") * Chromium 115.0.5790.13 * Mozilla Firefox 113.0 * WebKit 16.4 This version was also tested against the following stable channels: * Google Chrome 114 * Microsoft Edge 114 Version 1.34[​](#version-134 "Direct link to Version 1.34") ----------------------------------------------------------- ### Highlights[​](#highlights-5 "Direct link to Highlights") * New [locator.and\_()](/python/docs/api/class-locator#locator-and) to create a locator that matches both locators. button = page.get_by_role("button").and_(page.get_by_title("Subscribe")) * New events [browser\_context.on("console")](/python/docs/api/class-browsercontext#browser-context-event-console) and [browser\_context.on("dialog")](/python/docs/api/class-browsercontext#browser-context-event-dialog) to subscribe to any dialogs and console messages from any page from the given browser context. Use the new methods [console\_message.page](/python/docs/api/class-consolemessage#console-message-page) and [dialog.page](/python/docs/api/class-dialog#dialog-page) to pin-point event source. ### Browser Versions[​](#browser-versions-21 "Direct link to Browser Versions") * Chromium 114.0.5735.26 * Mozilla Firefox 113.0 * WebKit 16.4 This version was also tested against the following stable channels: * Google Chrome 113 * Microsoft Edge 113 Version 1.33[​](#version-133 "Direct link to Version 1.33") ----------------------------------------------------------- ### Locators Update[​](#locators-update "Direct link to Locators Update") * Use [locator.or\_()](/python/docs/api/class-locator#locator-or) to create a locator that matches either of the two locators. Consider a scenario where you'd like to click on a "New email" button, but sometimes a security settings dialog shows up instead. In this case, you can wait for either a "New email" button, or a dialog and act accordingly: new_email = page.get_by_role("button", name="New email")dialog = page.get_by_text("Confirm security settings")expect(new_email.or_(dialog)).is_visible()if (dialog.is_visible()): page.get_by_role("button", name="Dismiss").click()new_email.click() * Use new options [has\_not](/python/docs/api/class-locator#locator-filter-option-has-not) and [has\_not\_text](/python/docs/api/class-locator#locator-filter-option-has-not-text) in [locator.filter()](/python/docs/api/class-locator#locator-filter) to find elements that **do not match** certain conditions. row_locator = page.locator("tr")row_locator.filter(has_not_text="text in column 1").filter( has_not=page.get_by_role("button", name="column 2 button")).screenshot() * Use new web-first assertion [expect(locator).to\_be\_attached()](/python/docs/api/class-locatorassertions#locator-assertions-to-be-attached) to ensure that the element is present in the page's DOM. Do not confuse with the [expect(locator).to\_be\_visible()](/python/docs/api/class-locatorassertions#locator-assertions-to-be-visible) that ensures that element is both attached & visible. ### New APIs[​](#new-apis-6 "Direct link to New APIs") * [locator.or\_()](/python/docs/api/class-locator#locator-or) * New option [has\_not](/python/docs/api/class-locator#locator-filter-option-has-not) in [locator.filter()](/python/docs/api/class-locator#locator-filter) * New option [has\_not\_text](/python/docs/api/class-locator#locator-filter-option-has-not-text) in [locator.filter()](/python/docs/api/class-locator#locator-filter) * [expect(locator).to\_be\_attached()](/python/docs/api/class-locatorassertions#locator-assertions-to-be-attached) * New option [timeout](/python/docs/api/class-route#route-fetch-option-timeout) in [route.fetch()](/python/docs/api/class-route#route-fetch) ### ⚠️ Breaking change[​](#️-breaking-change "Direct link to ⚠️ Breaking change") * The `mcr.microsoft.com/playwright/python:v1.33.0` now serves a Playwright image based on Ubuntu Jammy. To use the focal-based image, please use `mcr.microsoft.com/playwright/python:v1.33.0-focal` instead. ### Browser Versions[​](#browser-versions-22 "Direct link to Browser Versions") * Chromium 113.0.5672.53 * Mozilla Firefox 112.0 * WebKit 16.4 This version was also tested against the following stable channels: * Google Chrome 112 * Microsoft Edge 112 Version 1.32[​](#version-132 "Direct link to Version 1.32") ----------------------------------------------------------- ### New APIs[​](#new-apis-7 "Direct link to New APIs") * Custom expect message, see [test assertions documentation](/python/docs/test-assertions#custom-expect-message). * New options [update\_mode](/python/docs/api/class-page#page-route-from-har-option-update-mode) and [update\_content](/python/docs/api/class-page#page-route-from-har-option-update-content) in [page.route\_from\_har()](/python/docs/api/class-page#page-route-from-har) and [browser\_context.route\_from\_har()](/python/docs/api/class-browsercontext#browser-context-route-from-har). * Chaining existing locator objects, see [locator docs](/python/docs/locators#matching-inside-a-locator) for details. * New option [name](/python/docs/api/class-tracing#tracing-start-chunk-option-name) in method [tracing.start\_chunk()](/python/docs/api/class-tracing#tracing-start-chunk). ### Browser Versions[​](#browser-versions-23 "Direct link to Browser Versions") * Chromium 112.0.5615.29 * Mozilla Firefox 111.0 * WebKit 16.4 This version was also tested against the following stable channels: * Google Chrome 111 * Microsoft Edge 111 Version 1.31[​](#version-131 "Direct link to Version 1.31") ----------------------------------------------------------- ### New APIs[​](#new-apis-8 "Direct link to New APIs") * New assertion [expect(locator).to\_be\_in\_viewport()](/python/docs/api/class-locatorassertions#locator-assertions-to-be-in-viewport) ensures that locator points to an element that intersects viewport, according to the [intersection observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API). from playwright.sync_api import expectlocator = page.get_by_role("button")# Make sure at least some part of element intersects viewport.expect(locator).to_be_in_viewport()# Make sure element is fully outside of viewport.expect(locator).not_to_be_in_viewport()# Make sure that at least half of the element intersects viewport.expect(locator).to_be_in_viewport(ratio=0.5) ### Miscellaneous[​](#miscellaneous-8 "Direct link to Miscellaneous") * DOM snapshots in trace viewer can be now opened in a separate window. * New option [max\_redirects](/python/docs/api/class-route#route-fetch-option-max-redirects) for method [route.fetch()](/python/docs/api/class-route#route-fetch). * Playwright now supports Debian 11 arm64. * Official [docker images](/python/docs/docker) now include Node 18 instead of Node 16. ### Browser Versions[​](#browser-versions-24 "Direct link to Browser Versions") * Chromium 111.0.5563.19 * Mozilla Firefox 109.0 * WebKit 16.4 This version was also tested against the following stable channels: * Google Chrome 110 * Microsoft Edge 110 Version 1.30[​](#version-130 "Direct link to Version 1.30") ----------------------------------------------------------- ### Browser Versions[​](#browser-versions-25 "Direct link to Browser Versions") * Chromium 110.0.5481.38 * Mozilla Firefox 108.0.2 * WebKit 16.4 This version was also tested against the following stable channels: * Google Chrome 109 * Microsoft Edge 109 Version 1.29[​](#version-129 "Direct link to Version 1.29") ----------------------------------------------------------- ### New APIs[​](#new-apis-9 "Direct link to New APIs") * New method [route.fetch()](/python/docs/api/class-route#route-fetch) and new option `json` for [route.fulfill()](/python/docs/api/class-route#route-fulfill): def handle_route(route: Route): # Fetch original settings. response = route.fetch() # Force settings theme to a predefined value. json = response.json() json["theme"] = "Solorized" # Fulfill with modified data. route.fulfill(json=json)page.route("**/api/settings", handle_route) * New method [locator.all()](/python/docs/api/class-locator#locator-all) to iterate over all matching elements: # Check all checkboxes!checkboxes = page.get_by_role("checkbox")for checkbox in checkboxes.all(): checkbox.check() * [locator.select\_option()](/python/docs/api/class-locator#locator-select-option) matches now by value or label: element.select_option("Red") ### Miscellaneous[​](#miscellaneous-9 "Direct link to Miscellaneous") * Option `postData` in method [route.continue\_()](/python/docs/api/class-route#route-continue) now supports [Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable") values. ### Browser Versions[​](#browser-versions-26 "Direct link to Browser Versions") * Chromium 109.0.5414.46 * Mozilla Firefox 107.0 * WebKit 16.4 This version was also tested against the following stable channels: * Google Chrome 108 * Microsoft Edge 108 Version 1.28[​](#version-128 "Direct link to Version 1.28") ----------------------------------------------------------- ### Playwright Tools[​](#playwright-tools "Direct link to Playwright Tools") * **Live Locators in CodeGen.** Generate a locator for any element on the page using "Explore" tool. ![Locator Explorer](https://user-images.githubusercontent.com/9798949/202293514-8e2eade6-c809-4b0a-864b-899dfcee3d84.png) ### New APIs[​](#new-apis-10 "Direct link to New APIs") * [locator.blur()](/python/docs/api/class-locator#locator-blur) * [locator.clear()](/python/docs/api/class-locator#locator-clear) ### Browser Versions[​](#browser-versions-27 "Direct link to Browser Versions") * Chromium 108.0.5359.29 * Mozilla Firefox 106.0 * WebKit 16.4 This version was also tested against the following stable channels: * Google Chrome 107 * Microsoft Edge 107 Version 1.27[​](#version-127 "Direct link to Version 1.27") ----------------------------------------------------------- ### Locators[​](#locators "Direct link to Locators") With these new APIs writing locators is a joy: * [page.get\_by\_text()](/python/docs/api/class-page#page-get-by-text) to locate by text content. * [page.get\_by\_role()](/python/docs/api/class-page#page-get-by-role) to locate by [ARIA role](https://www.w3.org/TR/wai-aria-1.2/#roles), [ARIA attributes](https://www.w3.org/TR/wai-aria-1.2/#aria-attributes) and [accessible name](https://w3c.github.io/accname/#dfn-accessible-name). * [page.get\_by\_label()](/python/docs/api/class-page#page-get-by-label) to locate a form control by associated label's text. * [page.get\_by\_test\_id()](/python/docs/api/class-page#page-get-by-test-id) to locate an element based on its `data-testid` attribute (other attribute can be configured). * [page.get\_by\_placeholder()](/python/docs/api/class-page#page-get-by-placeholder) to locate an input by placeholder. * [page.get\_by\_alt\_text()](/python/docs/api/class-page#page-get-by-alt-text) to locate an element, usually image, by its text alternative. * [page.get\_by\_title()](/python/docs/api/class-page#page-get-by-title) to locate an element by its title. page.get_by_label("User Name").fill("John")page.get_by_label("Password").fill("secret-password")page.get_by_role("button", name="Sign in").click()expect(page.get_by_text("Welcome, John!")).to_be_visible() All the same methods are also available on [Locator](/python/docs/api/class-locator "Locator"), [FrameLocator](/python/docs/api/class-framelocator "FrameLocator") and [Frame](/python/docs/api/class-frame "Frame") classes. ### Other highlights[​](#other-highlights "Direct link to Other highlights") * As announced in v1.25, Ubuntu 18 will not be supported as of Dec 2022. In addition to that, there will be no WebKit updates on Ubuntu 18 starting from the next Playwright release. ### Behavior Changes[​](#behavior-changes "Direct link to Behavior Changes") * [expect(locator).to\_have\_attribute()](/python/docs/api/class-locatorassertions#locator-assertions-to-have-attribute) with an empty value does not match missing attribute anymore. For example, the following snippet will succeed when `button` **does not** have a `disabled` attribute. expect(page.get_by_role("button")).to_have_attribute("disabled", "") ### Browser Versions[​](#browser-versions-28 "Direct link to Browser Versions") * Chromium 107.0.5304.18 * Mozilla Firefox 105.0.1 * WebKit 16.0 This version was also tested against the following stable channels: * Google Chrome 106 * Microsoft Edge 106 Version 1.26[​](#version-126 "Direct link to Version 1.26") ----------------------------------------------------------- ### Assertions[​](#assertions "Direct link to Assertions") * New option `enabled` for [expect(locator).to\_be\_enabled()](/python/docs/api/class-locatorassertions#locator-assertions-to-be-enabled). * [expect(locator).to\_have\_text()](/python/docs/api/class-locatorassertions#locator-assertions-to-have-text) now pierces open shadow roots. * New option `editable` for [expect(locator).to\_be\_editable()](/python/docs/api/class-locatorassertions#locator-assertions-to-be-editable). * New option `visible` for [expect(locator).to\_be\_visible()](/python/docs/api/class-locatorassertions#locator-assertions-to-be-visible). ### Other highlights[​](#other-highlights-1 "Direct link to Other highlights") * New option `max_redirects` for [api\_request\_context.get()](/python/docs/api/class-apirequestcontext#api-request-context-get) and others to limit redirect count. * Python 3.11 is now supported. ### Behavior Change[​](#behavior-change "Direct link to Behavior Change") A bunch of Playwright APIs already support the `wait_until: "domcontentloaded"` option. For example: page.goto("https://playwright.dev", wait_until="domcontentloaded") Prior to 1.26, this would wait for all iframes to fire the `DOMContentLoaded` event. To align with web specification, the `'domcontentloaded'` value only waits for the target frame to fire the `'DOMContentLoaded'` event. Use `wait_until="load"` to wait for all iframes. ### Browser Versions[​](#browser-versions-29 "Direct link to Browser Versions") * Chromium 106.0.5249.30 * Mozilla Firefox 104.0 * WebKit 16.0 This version was also tested against the following stable channels: * Google Chrome 105 * Microsoft Edge 105 Version 1.25[​](#version-125 "Direct link to Version 1.25") ----------------------------------------------------------- ### Announcements[​](#announcements-1 "Direct link to Announcements") * 🎁 We now ship Ubuntu 22.04 Jammy Jellyfish docker image: `mcr.microsoft.com/playwright/python:v1.34.0-jammy`. * 🪦 This is the last release with macOS 10.15 support (deprecated as of 1.21). * ⚠️ Ubuntu 18 is now deprecated and will not be supported as of Dec 2022. ### Browser Versions[​](#browser-versions-30 "Direct link to Browser Versions") * Chromium 105.0.5195.19 * Mozilla Firefox 103.0 * WebKit 16.0 This version was also tested against the following stable channels: * Google Chrome 104 * Microsoft Edge 104 Version 1.24[​](#version-124 "Direct link to Version 1.24") ----------------------------------------------------------- ### 🐂 Debian 11 Bullseye Support[​](#-debian-11-bullseye-support "Direct link to 🐂 Debian 11 Bullseye Support") Playwright now supports Debian 11 Bullseye on x86\_64 for Chromium, Firefox and WebKit. Let us know if you encounter any issues! Linux support looks like this: | | Ubuntu 20.04 | Ubuntu 22.04 | Debian 11 | :--- | :---: | :---: | :---: | :---: | | Chromium | ✅ | ✅ | ✅ | | WebKit | ✅ | ✅ | ✅ | | Firefox | ✅ | ✅ | ✅ | ### New introduction docs[​](#new-introduction-docs "Direct link to New introduction docs") We rewrote our Getting Started docs to be more end-to-end testing focused. Check them out on [playwright.dev](https://playwright.dev/python/docs/intro). Version 1.23[​](#version-123 "Direct link to Version 1.23") ----------------------------------------------------------- ### Network Replay[​](#network-replay "Direct link to Network Replay") Now you can record network traffic into a HAR file and re-use this traffic in your tests. To record network into HAR file: npx playwright open --save-har=github.har.zip https://github.com/microsoft Alternatively, you can record HAR programmatically: * Sync * Async context = browser.new_context(record_har_path="github.har.zip")# ... do stuff ...context.close() context = await browser.new_context(record_har_path="github.har.zip")# ... do stuff ...await context.close() Use the new methods [page.route\_from\_har()](/python/docs/api/class-page#page-route-from-har) or [browser\_context.route\_from\_har()](/python/docs/api/class-browsercontext#browser-context-route-from-har) to serve matching responses from the [HAR](http://www.softwareishard.com/blog/har-12-spec/) file: * Sync * Async context.route_from_har("github.har.zip") await context.route_from_har("github.har.zip") Read more in [our documentation](/python/docs/mock#mocking-with-har-files). ### Advanced Routing[​](#advanced-routing "Direct link to Advanced Routing") You can now use [route.fallback()](/python/docs/api/class-route#route-fallback) to defer routing to other handlers. Consider the following example: * Sync * Async # Remove a header from all requestsdef remove_header_handler(route: Route) -> None: headers = route.request.all_headers() if "if-none-match" in headers: del headers["if-none-match"] route.fallback(headers=headers)page.route("**/*", remove_header_handler)# Abort all imagesdef abort_images_handler(route: Route) -> None: if route.request.resource_type == "image": route.abort() else: route.fallback()page.route("**/*", abort_images_handler) # Remove a header from all requestsasync def remove_header_handler(route: Route) -> None: headers = await route.request.all_headers() if "if-none-match" in headers: del headers["if-none-match"] await route.fallback(headers=headers)await page.route("**/*", remove_header_handler)# Abort all imagesasync def abort_images_handler(route: Route) -> None: if route.request.resource_type == "image": await route.abort() else: await route.fallback()await page.route("**/*", abort_images_handler) Note that the new methods [page.route\_from\_har()](/python/docs/api/class-page#page-route-from-har) and [browser\_context.route\_from\_har()](/python/docs/api/class-browsercontext#browser-context-route-from-har) also participate in routing and could be deferred to. ### Web-First Assertions Update[​](#web-first-assertions-update "Direct link to Web-First Assertions Update") * New method [expect(locator).to\_have\_values()](/python/docs/api/class-locatorassertions#locator-assertions-to-have-values) that asserts all selected values of ``, `