Skip to content

Commit c2cc620

Browse files
Implement a11y protocol commands in puppeteer (#6160)
1 parent 22ee028 commit c2cc620

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Get the computed WAI-ARIA label of an element.
3+
*
4+
* @alias browser.getElementComputedLabel
5+
* @see https://w3c.github.io/webdriver/#get-computed-label
6+
* @param {string} elementId the id of an element returned in a previous call to Find Element(s)
7+
* @return {string} The result of computing the WAI-ARIA label of element.
8+
*/
9+
10+
import type DevToolsDriver from '../devtoolsdriver'
11+
12+
export default async function getElementComputedLabel (
13+
this: DevToolsDriver,
14+
{ elementId }: { elementId: string }
15+
) {
16+
const page = this.getPageHandle(true)
17+
const elementHandle = await this.elementStore.get(elementId)
18+
const snapshot = await page.accessibility.snapshot({
19+
root: elementHandle
20+
})
21+
22+
if (!snapshot) {
23+
return ''
24+
}
25+
26+
return snapshot.name
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Get the computed WAI-ARIA role of an element.
3+
*
4+
* @alias browser.getElementComputedRole
5+
* @see https://w3c.github.io/webdriver/#get-computed-role
6+
* @param {string} elementId the id of an element returned in a previous call to Find Element(s)
7+
* @return {string} The result of computing the WAI-ARIA role of element.
8+
*/
9+
10+
import type DevToolsDriver from '../devtoolsdriver'
11+
12+
export default async function getElementComputedRole (
13+
this: DevToolsDriver,
14+
{ elementId }: { elementId: string }
15+
) {
16+
const page = this.getPageHandle(true)
17+
const elementHandle = await this.elementStore.get(elementId)
18+
const snapshot = await page.accessibility.snapshot({
19+
root: elementHandle
20+
})
21+
22+
if (!snapshot) {
23+
return 'Ignored'
24+
}
25+
26+
return snapshot.role
27+
}

0 commit comments

Comments
 (0)