mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-07 11:46:42 +03:00
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:
parent
7a8eb15820
commit
80f46892cd
@ -328,7 +328,7 @@ export class InjectedScript {
|
|||||||
let labels: Element[] | NodeListOf<Element> | null | undefined = getAriaLabelledByElements(element);
|
let labels: Element[] | NodeListOf<Element> | null | undefined = getAriaLabelledByElements(element);
|
||||||
if (labels === null) {
|
if (labels === null) {
|
||||||
const ariaLabel = element.getAttribute('aria-label');
|
const ariaLabel = element.getAttribute('aria-label');
|
||||||
if (ariaLabel !== null)
|
if (ariaLabel !== null && !!ariaLabel.trim())
|
||||||
return matcher({ full: ariaLabel, immediate: [ariaLabel] });
|
return matcher({ full: ariaLabel, immediate: [ariaLabel] });
|
||||||
}
|
}
|
||||||
if (labels === null)
|
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');
|
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 }) => {
|
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>`);
|
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');
|
expect(await page.getByLabel('Other').evaluate(e => e.id)).toBe('target');
|
||||||
|
Loading…
Reference in New Issue
Block a user