Skip to main content

Function: byAriaLabel()

byAriaLabel(value, relative?): PartLocator

Defined in: packages/core/src/locators/byAriaLabel.ts:37

Locate elements by the verbatim value of their aria-label attribute.

This matches the literal aria-label attribute only — it does NOT resolve the computed accessible name (from aria-labelledby, an associated <label>, or text content), which is not CSS-expressible and is the job of the forthcoming name-aware findByRole (deferred — see #923).

Most commonly composed with byRole on the SAME element to tell two same-role siblings apart without relying on unstable (e.g. StyleX-hashed) class names. Use locatorUtil.and to compound the matchers onto one element:

import { byAriaLabel, byRole, locatorUtil } from '@atomic-testing/core';
const openButton = locatorUtil.and(byRole('button'), byAriaLabel('Open'));
const closeButton = locatorUtil.and(byRole('button'), byAriaLabel('Close'));

Parameters​

value​

string

Verbatim aria-label to match.

relative?​

LocatorRelativePosition = 'Descendant'

Relative position of the locator. Defaults to 'Descendant'.

Returns​

PartLocator

Example​

const close = byAriaLabel('Close');