Skip to main content

Auto-waiting

Introduction

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.

For example, for locator.click(), Playwright will ensure that:

Here is the complete list of actionability checks performed for each action:

ActionVisibleStableReceives EventsEnabledEditablelocator.check()YesYesYesYes-locator.click()YesYesYesYes-locator.dblclick()YesYesYesYes-locator.set_checked()YesYesYesYes-locator.tap()YesYesYesYes-locator.uncheck()YesYesYesYes-locator.hover()YesYesYes--locator.drag_to()YesYesYes--locator.screenshot()YesYes---locator.fill()Yes--YesYeslocator.clear()Yes--YesYeslocator.select_option()Yes--Yes-locator.select_text()Yes----locator.scroll_into_view_if_needed()-Yes---locator.blur()-----locator.dispatch_event()-----locator.focus()-----locator.press()-----locator.press_sequentially()-----locator.set_input_files()-----

Forcing actions

Some actions like locator.click() support force option that disables non-essential actionability checks, for example passing truthy force to locator.click() method will not check that the target element actually receives click events.

Assertions

Playwright includes auto-retrying assertions that remove flakiness by waiting until the condition is met, similarly to auto-waiting before actions.

AssertionDescriptionexpect(locator).to_be_attached()Element is attachedexpect(locator).to_be_checked()Checkbox is checkedexpect(locator).to_be_disabled()Element is disabledexpect(locator).to_be_editable()Element is editableexpect(locator).to_be_empty()Container is emptyexpect(locator).to_be_enabled()Element is enabledexpect(locator).to_be_focused()Element is focusedexpect(locator).to_be_hidden()Element is not visibleexpect(locator).to_be_in_viewport()Element intersects viewportexpect(locator).to_be_visible()Element is visibleexpect(locator).to_contain_text()Element contains textexpect(locator).to_have_attribute()Element has a DOM attributeexpect(locator).to_have_class()Element has a class propertyexpect(locator).to_have_count()List has exact number of childrenexpect(locator).to_have_css()Element has CSS propertyexpect(locator).to_have_id()Element has an IDexpect(locator).to_have_js_property()Element has a JavaScript propertyexpect(locator).to_have_text()Element matches textexpect(locator).to_have_value()Input has a valueexpect(locator).to_have_values()Select has options selectedexpect(page).to_have_title()Page has a titleexpect(page).to_have_url()Page has a URLexpect(response).to_be_ok()Response has an OK status

Learn more in the assertions guide.

Visible

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:

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:

Editable

Element is considered editable when it is enabled and is not readonly.

Element is readonly when:

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: