Skip to main content

Accessibility

Accessibility 类提供了检查 Chromium 的可访问性树的方法。可访问性树由 屏幕阅读器switches 等辅助技术使用。

¥The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by assistive technology such as screen readers or switches.

可访问性是一个非常特定于平台的东西。在不同的平台上,有不同的屏幕阅读器,可能会产生截然不同的输出。

¥Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might have wildly different output.

Chromium、Firefox 和 WebKit 的渲染引擎都有 "可达性树" 的概念,然后将其转换为不同平台特定的 API。可访问性命名空间提供对此可访问性树的访问。

¥Rendering engines of Chromium, Firefox and WebKit have a concept of "accessibility tree", which is then translated into different platform-specific APIs. Accessibility namespace gives access to this Accessibility Tree.

当从内部浏览器 AX 树转换为特定于平台的 AX 树或通过辅助技术本身时,大多数可访问性树都会被过滤掉。默认情况下,Playwright 尝试近似此过滤,仅公开树的 "interesting" 节点。

¥Most of the accessibility tree gets filtered out when converting from internal browser AX Tree to Platform-specific AX-Tree or by assistive technologies themselves. By default, Playwright tries to approximate this filtering, exposing only the "interesting" nodes of the tree.


已弃用

¥Deprecated

SnapshotAsync

Added before v1.9 accessibility.SnapshotAsync
已弃用

此方法已被弃用。如果你需要测试页面可访问性,请使用其他库,例如 Axe。请参阅我们的 Node.js guide 以了解与 Axe 的集成。

¥This method is deprecated. Please use other libraries such as Axe if you need to test page accessibility. See our Node.js guide for integration with Axe.

捕获可访问性树的当前状态。返回的对象表示页面的根可访问节点。

¥Captures the current state of the accessibility tree. The returned object represents the root accessible node of the page.

注意

Chromium 可访问性树包含大多数平台和大多数屏幕阅读器未使用的节点。Playwright 也会丢弃它们,以便更容易处理树,除非 InterestingOnly 设置为 false

¥The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers. Playwright will discard them as well for an easier to process tree, unless InterestingOnly is set to false.

用法

¥Usage

转储整个可访问性树的示例:

¥An example of dumping the entire accessibility tree:

var accessibilitySnapshot = await page.Accessibility.SnapshotAsync();
Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(accessibilitySnapshot));

记录焦点节点名称的示例:

¥An example of logging the focused node's name:

var accessibilitySnapshot = await page.Accessibility.SnapshotAsync();
Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(accessibilitySnapshot));

参数

¥Arguments

  • options AccessibilitySnapshotOptions?(可选)

    ¥options AccessibilitySnapshotOptions? (optional)

    • InterestingOnly bool? (optional)#

从树中修剪掉不感兴趣的节点。默认为 true

¥Prune uninteresting nodes from the tree. Defaults to true.

快照的根 DOM 元素。默认为整个页面。

¥The root DOM element for the snapshot. Defaults to the whole page.

返回

¥Returns