.getAccessibleName() Suggest edits
Returns the computed WAI-ARIA label of an element.
getAccessibleName()
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. Starting with v1.2
you can suppress element not found errors by specifying the suppressNotFoundErrors
option.
Usage
.getAccessibleName(selector, callback)
.getAccessibleName(using, selector, callback)
Parameters
Name | Type | description |
---|---|---|
using Optional |
string | 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. |
Returns
Type | description |
---|---|
string | The computed WAI-ARIA label of element. |
Example
module.exports = {
demoTest(browser) {
browser.getAccessibleName('[name="search"]', function(result) {
this.assert.equal(typeof result, 'object);
this.assert.equal(result.value, 'search input');
});
// with explicit locate strategy
browser.getAccessibleName('css selector', '[name="search"]', function(result) {
console.log('getAccessibleName result', result.value);
});
// with selector object - see https://nightwatchjs.org/guide#element-properties
browser.getAccessibleName({
selector: '[name="search"]',
index: 1
}, function(result) {
console.log('getAccessibleName result', result.value);
});
browser.getAccessibleName({
selector: '[name="search"]',
timeout: 2000 // overwrite the default timeout (in ms) to check if the element is present
}, function(result) {
console.log('getAccessibleName result', result.value);
});
},
demoTestAsync: async function(browser) {
const result = await browser.getAccessibleName('*[name="search"]');
console.log('getAccessibleName result', result);
}
}