Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore(dotnet): add examples to accessibility docs (#5702)

Anže Vodovnik986286a39629
diff --git a/docs/src/api/class-accessibility.md b/docs/src/api/class-accessibility.md
index 0e87623ca6..fa7abcc576 100644
--- a/docs/src/api/class-accessibility.md
+++ b/docs/src/api/class-accessibility.md
@@ -73,6 +73,11 @@ snapshot = page.accessibility.snapshot()
print(snapshot)
```
+```csharp
+var accessibilitySnapshot = await Page.Accessibility.SnapshotAsync();
+Console.WriteLine(accessibilitySnapshot);
+```
+
An example of logging the focused node's name:
```js
@@ -91,6 +96,29 @@ function findFocusedNode(node) {
}
```
+```csharp
+Func<AccessibilitySnapshotResult, AccessibilitySnapshotResult> findFocusedNode = root =>
+{
+ var nodes = new Stack<AccessibilitySnapshotResult>(new[] { root });
+ while (nodes.Count > 0)
+ {
+ var node = nodes.Pop();
+ if (node.Focused) return node;
+ foreach (var innerNode in node.Children)
+ {
+ nodes.Push(innerNode);
+ }
+ }
+
+ return null;
+};
+
+var accessibilitySnapshot = await Page.Accessibility.SnapshotAsync();
+var focusedNode = findFocusedNode(accessibilitySnapshot);
+if(focusedNode != null)
+ Console.WriteLine(focusedNode.Name);
+```
+
```java
// FIXME
String snapshot = page.accessibility().snapshot();
@@ -127,7 +155,7 @@ if node:
```
## async method: Accessibility.snapshot
-* langs: csharp, java
+* langs: java
- returns: <[null]|[string]>
### option: Accessibility.snapshot.interestingOnly