Auto-waiting
Playwright conducts a series of actionability verifications on the elements prior to executing actions to guarantee that these actions function as intended. It automatically waits for all pertinent checks to be completed successfully before carrying out the requested action. Should the necessary checks fail to pass within the specified timeout, the action will result in a TimeoutError.
For instance, in the case of locator.click(), Playwright will verify that:
- locator resolves to exactly one element
- 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
Here is the comprehensive list of actionability checks conducted for every action:
Action
Visible
Stable
Receives Events
Enabled
Editable
Forcing actions
Certain functions, such as locator.click(), offer a force option that bypasses non-essential actionability checks. For instance, providing a truthy value for the force parameter in the locator.click() method will prevent verification that the intended element truly registers click events.
Visible
Element is considered visible when it has a 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.
Stable
Element is considered stable when it has maintained the same bounding box for at least two consecutive animation frames.
Enabled
Element is considered enabled when it is not disabled.
Element is disabled when:
- it is a <button>, <select>, <input>, <textarea>, <option> or <optgroup> with a [disabled] attribute;
- it is a <button>, <select>, <input>, <textarea>, <option> or <optgroup> that is a part of a <fieldset> with a [disabled] attribute;
- it is a descendant of an element with [aria-disabled=true] attribute.
Editable
Element is considered editable when it is enabled and is not readonly.
Element is readonly when:
- it is a <select>, <input> or <textarea> with a [readonly] attribute;
- it has an [aria-readonly=true] attribute and an aria role that supports it.
Receives Events
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).
For example, consider a scenario where Playwright will click Sign Up button regardless of when the locator.click() call was made:
- 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.
Playwright Essentials: A Step-by-Step Journey into Test Automation
Part 01: Master Playwright Testing – Framework from Scratch Guide
Part 02: How to install Playwright
Part 03: Basic Playwright Test Structure
Part 04: Importance of Playwright configuration file and its details to run the tests
Part 05: Writing Tests in PlayWright
Part 06: Playwright Actions Illustrated
Part 07: Auto-waiting