fix(getByLabel): ignore empty aria-label (#22935)
Accessible name computation ignores empty aria-label, and so should getByLabel. Fixes #22915.
This commit is contained in:
Родитель
7a8eb15820
Коммит
80f46892cd
|
@ -328,7 +328,7 @@ export class InjectedScript {
|
|||
let labels: Element[] | NodeListOf<Element> | null | undefined = getAriaLabelledByElements(element);
|
||||
if (labels === null) {
|
||||
const ariaLabel = element.getAttribute('aria-label');
|
||||
if (ariaLabel !== null)
|
||||
if (ariaLabel !== null && !!ariaLabel.trim())
|
||||
return matcher({ full: ariaLabel, immediate: [ariaLabel] });
|
||||
}
|
||||
if (labels === null)
|
||||
|
|
|
@ -117,6 +117,11 @@ it('getByLabel should work with aria-label', async ({ page }) => {
|
|||
expect(await page.getByLabel('Name').evaluate(e => e.id)).toBe('target');
|
||||
});
|
||||
|
||||
it('getByLabel should ignore empty aria-label', async ({ page }) => {
|
||||
await page.setContent(`<label for=target>Last Name</label><input id=target type=text aria-label>`);
|
||||
expect(await page.getByLabel('Last Name').evaluate(e => e.id)).toBe('target');
|
||||
});
|
||||
|
||||
it('getByLabel should prioritize aria-labelledby over aria-label', async ({ page }) => {
|
||||
await page.setContent(`<label id=other-label>Other</label><input id=target aria-label="Name" aria-labelledby=other-label>`);
|
||||
expect(await page.getByLabel('Other').evaluate(e => e.id)).toBe('target');
|
||||
|
|
Загрузка…
Ссылка в новой задаче