Skip to content

Auto-waiting

Source URL: https://playwright.dev/docs/actionability

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:

  • 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 complete list of actionability checks performed for each action:

ActionVisibleStableReceives EventsEnabledEditablelocator.check()YesYesYesYes-locator.click()YesYesYesYes-locator.dblclick()YesYesYesYes-locator.setChecked()YesYesYesYes-locator.tap()YesYesYesYes-locator.uncheck()YesYesYesYes-locator.hover()YesYesYes--locator.dragTo()YesYesYes--locator.screenshot()YesYes---locator.fill()Yes--YesYeslocator.clear()Yes--YesYeslocator.selectOption()Yes--Yes-locator.selectText()Yes----locator.scrollIntoViewIfNeeded()-Yes---locator.blur()-----locator.dispatchEvent()-----locator.focus()-----locator.press()-----locator.pressSequentially()-----locator.setInputFiles()-----

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.

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

AssertionDescriptionexpect(locator).toBeAttached()Element is attachedexpect(locator).toBeChecked()Checkbox is checkedexpect(locator).toBeDisabled()Element is disabledexpect(locator).toBeEditable()Element is editableexpect(locator).toBeEmpty()Container is emptyexpect(locator).toBeEnabled()Element is enabledexpect(locator).toBeFocused()Element is focusedexpect(locator).toBeHidden()Element is not visibleexpect(locator).toBeInViewport()Element intersects viewportexpect(locator).toBeVisible()Element is visibleexpect(locator).toContainText()Element contains textexpect(locator).toHaveAttribute()Element has a DOM attributeexpect(locator).toHaveClass()Element has a class propertyexpect(locator).toHaveCount()List has exact number of childrenexpect(locator).toHaveCSS()Element has CSS propertyexpect(locator).toHaveId()Element has an IDexpect(locator).toHaveJSProperty()Element has a JavaScript propertyexpect(locator).toHaveText()Element matches textexpect(locator).toHaveValue()Input has a valueexpect(locator).toHaveValues()Select has options selectedexpect(page).toHaveTitle()Page has a titleexpect(page).toHaveURL()Page has a URLexpect(response).toBeOK()Response has an OK status

Learn more in the assertions guide.

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.

Element is considered stable when it has maintained the same bounding box for at least two consecutive animation frames.

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.

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.

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.