.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-selected
attribute withtrue
orfalse
value.checked
- picks an element that has thearea-checked
attribute withtrue
orfalse
value.pressed
- picks an element that has thearea-pressed
attribute withtrue
orfalse
value.current
- picks an element that has thearea-current
attribute withtrue
orfalse
value.level
- picks an element that has thearea-level
attribute withtrue
orfalse
value. This option is suitable only for theheading
role.expanded
- picks an element that has thearea-expanded
attribute withtrue
orfalse
value.
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 | |
options Optional |
[object Object] |
Returns
Type | description |
---|---|
ScopedWebElement |