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:

  • 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 EventsEnabledEditable
Locator.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--YesYes
Locator.clear()Yes--YesYes
Locator.selectOption()Yes--Yes-
Locator.selectText()Yes----
Locator.scrollIntoViewIfNeeded()-Yes---
Locator.blur()-----
Locator.dispatchEvent()-----
Locator.focus()-----
Locator.press()-----
Locator.pressSequentially()-----
Locator.setInputFiles()-----

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.

AssertionDescription
assertThat(locator).isAttached()Element is attached
assertThat(locator).isChecked()Checkbox is checked
assertThat(locator).isDisabled()Element is disabled
assertThat(locator).isEditable()Element is editable
assertThat(locator).isEmpty()Container is empty
assertThat(locator).isEnabled()Element is enabled
assertThat(locator).isFocused()Element is focused
assertThat(locator).isHidden()Element is not visible
assertThat(locator).isInViewport()Element intersects viewport
assertThat(locator).isVisible()Element is visible
assertThat(locator).containsText()Element contains text
assertThat(locator).hasAttribute()Element has a DOM attribute
assertThat(locator).hasClass()Element has a class property
assertThat(locator).hasCount()List has exact number of children
assertThat(locator).hasCSS()Element has CSS property
assertThat(locator).hasId()Element has an ID
assertThat(locator).hasJSProperty()Element has a JavaScript property
assertThat(locator).hasText()Element matches text
assertThat(locator).hasValue()Input has a value
assertThat(locator).hasValues()Select has options selected
assertThat(page).hasTitle()Page has a title
assertThat(page).hasURL()Page has a URL
assertThat(response).isOK()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:

  • 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 unless it is a <button>, <select>, <input> or <textarea> with a disabled property.

Editable

Element is considered editable when it is enabled and does not have readonly property set.

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.