⚡️ New "strict" mode
Selector ambiguity is a common problem in automation testing. **"strict" mode**
ensures that your selector points to a single element and throws otherwise.
Pass `strict = true` into your action calls to opt in.
py
This will throw if you have more than one button!
page.click('button', strict=true)
📍 New [**Locators API**](https://playwright.dev/python/docs/api/class-locator)
Locator represents a view to the element(s) on the page. It captures the logic sufficient to retrieve the element at any given moment.
The difference between the [Locator](https://playwright.dev/python/docs/api/class-locator) and [ElementHandle](https://playwright.dev/python/docs/api/class-elementhandle) is that the latter points to a particular element, while [Locator](https://playwright.dev/python/docs/api/class-locator) captures the logic of how to retrieve that element.
Also, locators are **"strict" by default**!
py
locator = page.locator('button')
locator.click()
Learn more in the [documentation](https://playwright.dev/python/docs/api/class-locator).
🧩 Experimental [**React**](https://playwright.dev/python/docs/selectors#react-selectors) and [**Vue**](https://playwright.dev/python/docs/selectors#vue-selectors) selector engines
React and Vue selectors allow selecting elements by its component name and/or property values. The syntax is very similar to [attribute selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors) and supports all attribute selector operators.
py
page.click('_react=SubmitButton[enabled=true]')
page.click('_vue=submit-button[enabled=true]')
Learn more in the [react selectors documentation](https://playwright.dev/python/docs/selectors#react-selectors) and the [vue selectors documentation](https://playwright.dev/python/docs/selectors#vue-selectors).
✨ New [**`nth`**](https://playwright.dev/python/docs/selectors#n-th-element-selector) and [**`visible`**](https://playwright.dev/python/docs/selectors#selecting-visible-elements) selector engines
- [`nth`](https://playwright.dev/python/docs/selectors#n-th-element-selector) selector engine is equivalent to the `:nth-match` pseudo class, but could be combined with other selector engines.
- [`visible`](https://playwright.dev/python/docs/selectors#selecting-visible-elements) selector engine is equivalent to the `:visible` pseudo class, but could be combined with other selector engines.
py
select the first button among all buttons
button.click('button >> nth=0')
or if you are using locators, you can use first(), nth() and last()
page.locator('button').first().click()
click a visible button
button.click('button >> visible=true')
Browser Versions
- Chromium 94.0.4595.0
- Mozilla Firefox 91.0
- WebKit 15.0
This version of Playwright was also tested against the following stable channels:
- Google Chrome 92
- Microsoft Edge 92