* Locate elements by ARIA role using WebdriverIO accessibility selectors * * @param {object} locator - role locator object { role: string, text?: string, exact?: boolean }
(locator)
| 991 | * @param {object} locator - role locator object { role: string, text?: string, exact?: boolean } |
| 992 | */ |
| 993 | async _locateByRole(locator) { |
| 994 | const role = locator.role |
| 995 | |
| 996 | if (!locator.text) { |
| 997 | return this.browser.$$(`[role="${role}"]`) |
| 998 | } |
| 999 | |
| 1000 | const elements = await this.browser.$$(`[role="${role}"]`) |
| 1001 | const filteredElements = [] |
| 1002 | const matchFn = locator.exact === true |
| 1003 | ? t => t === locator.text |
| 1004 | : t => t && t.includes(locator.text) |
| 1005 | |
| 1006 | for (const element of elements) { |
| 1007 | const texts = await getElementTextAttributes.call(this, element) |
| 1008 | if (texts.some(matchFn)) { |
| 1009 | filteredElements.push(element) |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | return filteredElements |
| 1014 | } |
| 1015 | |
| 1016 | /** |
| 1017 | * {{> grabWebElements }} |
no test coverage detected