MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / _locateByRole

Method _locateByRole

lib/helper/WebDriver.js:993–1014  ·  view source on GitHub ↗

* Locate elements by ARIA role using WebdriverIO accessibility selectors * * @param {object} locator - role locator object { role: string, text?: string, exact?: boolean }

(locator)

Source from the content-addressed store, hash-verified

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 }}

Callers 2

_locateMethod · 0.95
selectOptionMethod · 0.95

Calls 3

$$Method · 0.80
includesMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected