2021-01-01 15:17:27 -08:00
---
id: actionability
2021-01-17 21:09:40 -08:00
title: "Auto-waiting"
2021-01-01 15:17:27 -08:00
---
2020-12-30 18:04:51 -08:00
2023-10-06 15:08:51 +02:00
## Introduction
2021-01-17 21:09:40 -08:00
Playwright performs a range of actionability checks on the elements before making actions to ensure these actions
behave as expected. It auto-waits for all the relevant checks to pass and only then performs the requested action. If the required checks do not pass within the given `timeout` , action fails with the `TimeoutError` .
2020-12-30 18:04:51 -08:00
2024-01-12 09:33:42 -08:00
For example, for [`method: Locator.click` ], Playwright will ensure that:
- locator resolves to an exactly one element
2021-01-17 21:09:40 -08:00
- element is [Visible]
- element is [Stable], as in not animating or completed animation
- element [Receives Events], as in not obscured by other elements
- element is [Enabled]
2021-01-06 11:59:29 -08:00
2021-01-17 21:09:40 -08:00
Here is the complete list of actionability checks performed for each action:
2021-01-06 11:59:29 -08:00
2024-01-12 09:33:42 -08:00
| Action | [Visible] | [Stable] | [Receives Events] | [Enabled] | [Editable] |
| :- | :-: | :-: | :-: | :-: | :-: |
| [`method: Locator.check` ] | Yes | Yes | Yes | Yes | - |
| [`method: Locator.click` ] | Yes | Yes | Yes | Yes | - |
| [`method: Locator.dblclick` ] | Yes | Yes | Yes | Yes | - |
| [`method: Locator.setChecked` ] | Yes | Yes | Yes | Yes | - |
| [`method: Locator.tap` ] | Yes | Yes | Yes | Yes | - |
| [`method: Locator.uncheck` ] | Yes | Yes | Yes | Yes | - |
| [`method: Locator.hover` ] | Yes | Yes | Yes | - | - |
| [`method: Locator.dragTo` ] | Yes | Yes | Yes | - | - |
| [`method: Locator.screenshot` ] | Yes | Yes | - | - | - |
| [`method: Locator.fill` ] | Yes | - | - | Yes | Yes |
| [`method: Locator.clear` ] | Yes | - | - | Yes | Yes |
| [`method: Locator.selectOption` ] | Yes | - | - | Yes | - |
| [`method: Locator.selectText` ] | Yes | - | - | - | - |
| [`method: Locator.scrollIntoViewIfNeeded` ] | - | Yes | - | - | - |
| [`method: Locator.blur` ] | - | - | - | - | - |
| [`method: Locator.dispatchEvent` ] | - | - | - | - | - |
| [`method: Locator.focus` ] | - | - | - | - | - |
| [`method: Locator.press` ] | - | - | - | - | - |
| [`method: Locator.pressSequentially` ] | - | - | - | - | - |
| [`method: Locator.setInputFiles` ] | - | - | - | - | - |
2021-01-17 21:09:40 -08:00
## Forcing actions
2024-01-12 09:33:42 -08:00
Some actions like [`method: Locator.click` ] support `force` option that disables non-essential actionability checks,
for example passing truthy `force` to [`method: Locator.click` ] method will not check that the target element actually
2021-01-17 21:09:40 -08:00
receives click events.
## Assertions
2024-01-12 09:33:42 -08:00
Playwright includes auto-retrying assertions that remove flakiness by waiting until the condition is met, similarly to auto-waiting before actions.
| Assertion | Description |
| :- | :- |
| [`method: LocatorAssertions.toBeAttached` ] | Element is attached |
| [`method: LocatorAssertions.toBeChecked` ] | Checkbox is checked |
| [`method: LocatorAssertions.toBeDisabled` ] | Element is disabled |
| [`method: LocatorAssertions.toBeEditable` ] | Element is editable |
| [`method: LocatorAssertions.toBeEmpty` ] | Container is empty |
| [`method: LocatorAssertions.toBeEnabled` ] | Element is enabled |
| [`method: LocatorAssertions.toBeFocused` ] | Element is focused |
| [`method: LocatorAssertions.toBeHidden` ] | Element is not visible |
| [`method: LocatorAssertions.toBeInViewport` ] | Element intersects viewport |
| [`method: LocatorAssertions.toBeVisible` ] | Element is visible |
| [`method: LocatorAssertions.toContainText` ] | Element contains text |
| [`method: LocatorAssertions.toHaveAttribute` ] | Element has a DOM attribute |
| [`method: LocatorAssertions.toHaveClass` ] | Element has a class property |
| [`method: LocatorAssertions.toHaveCount` ] | List has exact number of children |
| [`method: LocatorAssertions.toHaveCSS` ] | Element has CSS property |
| [`method: LocatorAssertions.toHaveId` ] | Element has an ID |
| [`method: LocatorAssertions.toHaveJSProperty` ] | Element has a JavaScript property |
| [`method: LocatorAssertions.toHaveText` ] | Element matches text |
| [`method: LocatorAssertions.toHaveValue` ] | Input has a value |
| [`method: LocatorAssertions.toHaveValues` ] | Select has options selected |
| [`method: PageAssertions.toHaveTitle` ] | Page has a title |
| [`method: PageAssertions.toHaveURL` ] | Page has a URL |
| [`method: APIResponseAssertions.toBeOK` ] | Response has an OK status |
Learn more in the [assertions guide ](./test-assertions.md ).
2021-01-17 21:09:40 -08:00
## Visible
2020-12-30 18:04:51 -08:00
2024-01-12 09:38:23 -08:00
Element is considered visible when it has non-empty bounding box and does not have `visibility:hidden` computed style.
Note that according to this definition:
* Elements of zero size **are not** considered visible.
* Elements with `display:none` **are not** considered visible.
* Elements with `opacity:0` **are** considered visible.
2020-12-30 18:04:51 -08:00
2021-01-17 21:09:40 -08:00
## Stable
2020-12-30 18:04:51 -08:00
Element is considered stable when it has maintained the same bounding box for at least two consecutive animation frames.
2021-01-17 21:09:40 -08:00
## Enabled
2020-12-30 18:04:51 -08:00
2022-05-25 12:05:17 -07:00
Element is considered enabled unless it is a `<button>` , `<select>` , `<input>` or `<textarea>` with a `disabled` property.
2020-12-30 18:04:51 -08:00
2021-01-17 21:09:40 -08:00
## Editable
2020-12-30 18:04:51 -08:00
2021-01-08 12:27:54 -08:00
Element is considered editable when it is [enabled] and does not have `readonly` property set.
2020-12-30 18:04:51 -08:00
2021-01-17 21:09:40 -08:00
## Receives Events
2020-12-30 18:04:51 -08:00
Element is considered receiving pointer events when it is the hit target of the pointer event at the action point. For example, when clicking at the point `(10;10)` , Playwright checks whether some other element (usually an overlay) will instead capture the click at `(10;10)` .
2024-01-12 09:33:42 -08:00
For example, consider a scenario where Playwright will click `Sign Up` button regardless of when the [`method: Locator.click` ] call was made:
2020-12-30 18:04:51 -08:00
- page is checking that user name is unique and `Sign Up` button is disabled;
- after checking with the server, the disabled `Sign Up` button is replaced with another one that is now enabled.
[Visible]: #visible "Visible"
[Stable]: #stable "Stable"
[Enabled]: #enabled "Enabled"
[Editable]: #editable "Editable"
2021-01-17 21:09:40 -08:00
[Receives Events]: #receives -events "Receives Events"