.findByRole() Suggest edits
Since: 3.0.0Search for an element on the page that meets the provided ARIA role.
Element can be searched by using another element as the starting point.
You can pass some options to narrow the search:
selected- picks an element that has thearea-selectedattribute withtrueorfalsevalue.checked- picks an element that has thearea-checkedattribute withtrueorfalsevalue.pressed- picks an element that has thearea-pressedattribute withtrueorfalsevalue.current- picks an element that has thearea-currentattribute withtrueorfalsevalue.level- picks an element that has thearea-levelattribute withtrueorfalsevalue. This option is suitable only for theheadingrole.expanded- picks an element that has thearea-expandedattribute withtrueorfalsevalue.
Usage
browser.element.findByRole(role, [options])
Example
export default {
demoTest(browser: NightwatchAPI): void {
const comboboxes = browser.element.findByRole('combobox');
const headings = browser.element.findByRole('heading', { level: 2 });
}
}
Parameters
| Name | Type | description |
|---|---|---|
role |
string | |
optionsOptional |
[object Object] |
Returns
| Type | description |
|---|---|
| ScopedWebElement |