playwright_rs/protocol/accessibility.rs
1// Accessibility — accessibility tree snapshots
2//
3// See: https://playwright.dev/docs/api/class-accessibility
4
5use crate::error::Result;
6use crate::protocol::page::Page;
7use serde_json::Value;
8
9/// Options for `Accessibility::snapshot`.
10///
11/// See: <https://playwright.dev/docs/api/class-accessibility#accessibility-snapshot>
12#[derive(Debug, Default, Clone)]
13#[non_exhaustive]
14pub struct AccessibilitySnapshotOptions {
15 /// Whether to prune uninteresting nodes from the tree.
16 ///
17 /// Defaults to `true`.
18 pub interesting_only: Option<bool>,
19
20 /// The root element for the snapshot.
21 ///
22 /// When not set, the snapshot is taken from the entire page.
23 pub root: Option<crate::protocol::ElementHandle>,
24}
25
26/// Provides accessibility-tree inspection methods on a page.
27///
28/// Access via [`Page::accessibility`].
29///
30/// See: <https://playwright.dev/docs/api/class-accessibility>
31#[derive(Clone)]
32pub struct Accessibility {
33 page: Page,
34}
35
36impl Accessibility {
37 pub(crate) fn new(page: Page) -> Self {
38 Self { page }
39 }
40
41 /// Captures the current state of the page's accessibility tree.
42 ///
43 /// Returns the accessibility tree as a JSON `Value` (tree of nodes with
44 /// `role`, `name`, `value`, `children`, etc.), or `null` when there is no
45 /// accessibility tree.
46 ///
47 /// # Errors
48 ///
49 /// Returns error if the RPC call fails or the browser has been closed.
50 ///
51 /// See: <https://playwright.dev/docs/api/class-accessibility#accessibility-snapshot>
52 pub async fn snapshot(&self, options: Option<AccessibilitySnapshotOptions>) -> Result<Value> {
53 self.page.accessibility_snapshot(options).await
54 }
55}