mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
118 lines
7.3 KiB
Markdown
118 lines
7.3 KiB
Markdown
---
|
|
id: actionability
|
|
title: "Actionability"
|
|
---
|
|
|
|
Playwright does a range of actionability checks on the elements before performing certain actions. These checks ensure that action behaves as expected, for example Playwright does not click on a disabled button.
|
|
|
|
Playwright waits until all the relevant actionability checks pass before performing an action. This means that action will fail with `TimeoutError` if checks do not pass within the specified `timeout`.
|
|
|
|
Some actions like `page.click()` support `{force: true}` option that disable non-essential actionability checks, for example passing `force` to `click()` method will not check that the target element actually receives click events.
|
|
|
|
| Actions | Performed checks |
|
|
| ------ | ------- |
|
|
| `check()`<br></br>`click()`<br></br>`dblclick()`<br></br>`tap()`<br></br>`uncheck()` | [Visible]<br></br>[Stable]<br></br>[Enabled]<br></br>[Receiving Events]<br></br>[Attached] |
|
|
| `hover()` | [Visible]<br></br>[Stable]<br></br>[Receiving Events]<br></br>[Attached] |
|
|
| `fill()` | [Visible]<br></br>[Enabled]<br></br>[Editable]<br></br>[Attached] |
|
|
| `dispatchEvent()`<br></br>`focus()`<br></br>`press()`<br></br>`setInputFiles()`<br></br>`selectOption()`<br></br>`type()` | [Attached] |
|
|
| `scrollIntoViewIfNeeded()`<br></br>`screenshot()` | [Visible]<br></br>[Stable]<br></br>[Attached] |
|
|
| `selectText()` | [Visible]<br></br>[Attached] |
|
|
| `getAttribute()`<br></br>`innerText()`<br></br>`innerHTML()`<br></br>`textContent()` | [Attached] |
|
|
|
|
### Visible
|
|
|
|
Element is considered visible when it has non-empty bounding box and does not have `visibility:hidden` computed style. Note that elements of zero size or with `display:none` are not 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 a `<button>`, `<select>` or `<input>` with a `disabled` property set.
|
|
|
|
### Editable
|
|
|
|
Element is considered editable when it does not have `readonly` property set.
|
|
|
|
### Receiving 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)`.
|
|
|
|
### Attached
|
|
|
|
Element is considered attached when it is [connected](https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected) to a Document or a ShadowRoot.
|
|
|
|
Attached check differs between selector-based and handle-based actions, like `page.click(selector, options)` as opposite to `elementHandle.click(options)`:
|
|
- For selector-based actions, Playwright first waits for an element matching `selector` to be attached to the DOM, and then checks that element is still attached before performing the action. If element was detached, the action is retried from the start.
|
|
- For handle-based actions, Playwright throws if the element is not attached.
|
|
|
|
For example, consider a scenario where Playwright will click `Sign Up` button regardless of when the `page.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.
|
|
|
|
[Visible]: #visible "Visible"
|
|
[Stable]: #stable "Stable"
|
|
[Enabled]: #enabled "Enabled"
|
|
[Editable]: #editable "Editable"
|
|
[Receiving Events]: #receiving-events "Receiving Events"
|
|
[Attached]: #attached "Attached"
|
|
|
|
[Playwright]: api/class-playwright.md "Playwright"
|
|
[Browser]: api/class-browser.md "Browser"
|
|
[BrowserContext]: api/class-browsercontext.md "BrowserContext"
|
|
[Page]: api/class-page.md "Page"
|
|
[Frame]: api/class-frame.md "Frame"
|
|
[ElementHandle]: api/class-elementhandle.md "ElementHandle"
|
|
[JSHandle]: api/class-jshandle.md "JSHandle"
|
|
[ConsoleMessage]: api/class-consolemessage.md "ConsoleMessage"
|
|
[Dialog]: api/class-dialog.md "Dialog"
|
|
[Download]: api/class-download.md "Download"
|
|
[Video]: api/class-video.md "Video"
|
|
[FileChooser]: api/class-filechooser.md "FileChooser"
|
|
[Keyboard]: api/class-keyboard.md "Keyboard"
|
|
[Mouse]: api/class-mouse.md "Mouse"
|
|
[Touchscreen]: api/class-touchscreen.md "Touchscreen"
|
|
[Request]: api/class-request.md "Request"
|
|
[Response]: api/class-response.md "Response"
|
|
[Selectors]: api/class-selectors.md "Selectors"
|
|
[Route]: api/class-route.md "Route"
|
|
[WebSocket]: api/class-websocket.md "WebSocket"
|
|
[TimeoutError]: api/class-timeouterror.md "TimeoutError"
|
|
[Accessibility]: api/class-accessibility.md "Accessibility"
|
|
[Worker]: api/class-worker.md "Worker"
|
|
[BrowserServer]: api/class-browserserver.md "BrowserServer"
|
|
[BrowserType]: api/class-browsertype.md "BrowserType"
|
|
[Logger]: api/class-logger.md "Logger"
|
|
[ChromiumBrowser]: api/class-chromiumbrowser.md "ChromiumBrowser"
|
|
[ChromiumBrowserContext]: api/class-chromiumbrowsercontext.md "ChromiumBrowserContext"
|
|
[ChromiumCoverage]: api/class-chromiumcoverage.md "ChromiumCoverage"
|
|
[CDPSession]: api/class-cdpsession.md "CDPSession"
|
|
[FirefoxBrowser]: api/class-firefoxbrowser.md "FirefoxBrowser"
|
|
[WebKitBrowser]: api/class-webkitbrowser.md "WebKitBrowser"
|
|
[Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array"
|
|
[Buffer]: https://nodejs.org/api/buffer.html#buffer_class_buffer "Buffer"
|
|
[ChildProcess]: https://nodejs.org/api/child_process.html "ChildProcess"
|
|
[Element]: https://developer.mozilla.org/en-US/docs/Web/API/element "Element"
|
|
[Error]: https://nodejs.org/api/errors.html#errors_class_error "Error"
|
|
[Evaluation Argument]: ./core-concepts.md#evaluationargument "Evaluation Argument"
|
|
[Map]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map "Map"
|
|
[Object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object"
|
|
[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise"
|
|
[RegExp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp "RegExp"
|
|
[Serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable"
|
|
[UIEvent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail"
|
|
[URL]: https://nodejs.org/api/url.html "URL"
|
|
[USKeyboardLayout]: ../src/usKeyboardLayout.ts "USKeyboardLayout"
|
|
[UnixTime]: https://en.wikipedia.org/wiki/Unix_time "Unix Time"
|
|
[boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean"
|
|
[function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function"
|
|
[iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols "Iterator"
|
|
[null]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null "null"
|
|
[number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number"
|
|
[origin]: https://developer.mozilla.org/en-US/docs/Glossary/Origin "Origin"
|
|
[selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector"
|
|
[Readable]: https://nodejs.org/api/stream.html#stream_class_stream_readable "Readable"
|
|
[string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "string"
|
|
[xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath"
|