Returns the computed WAI-ARIA role of an element.

The command getAriaRole() will automatically wait for the element to be present (until the specified timeout). If the element is not found, an error is thrown which will cause the test to fail. You can suppress element not found errors by specifying the selector argument as an object and passing the suppressNotFoundErrors = true option.

For more info on working with DOM elements in Nightwatch, refer to the Finding & interacting with DOM Elements guide page.


.getAriaRole(selector, [callback])
.getAriaRole(using, selector, [callback])


Name Type description

The locator strategy to use. See W3C Webdriver - locator strategies

selector string

The CSS/Xpath selector used to locate the element.

callback function

Callback function which is called with the result value.


Type description
string The computed WAI-ARIA role of element.


module.exports = {
  demoTest(browser) {
    browser.getAriaRole('[name="search"]', function(result) {
      this.assert.equal(typeof result, 'object');
      this.assert.equal(result.value, 'combobox');

    // with explicit locate strategy
    browser.getAriaRole('css selector', '[name="search"]', function(result) {
      console.log('getAriaRole result', result.value);

    // with selector object - see
      selector: '[name="search"]',
      index: 1
    }, function(result) {
      console.log('getAriaRole result', result.value);

      selector: '[name="search"]',
      timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
    }, function(result) {
      console.log('getAriaRole result', result.value);

  demoTestAsync: async function(browser) {
    const result = await browser.getAriaRole('*[name="search"]');
    console.log('getAriaRole result', result);

W3C WebDriver spec