mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-03 07:51:12 +03:00
parent
3ad65e7ce8
commit
24f2ccb4ca
@ -298,6 +298,11 @@ export class InjectedScript {
|
||||
const allElements = this._evaluator._queryCSS({ scope: root as Document | Element, pierceShadow: true }, '*');
|
||||
return allElements.filter(element => {
|
||||
let labels: Element[] | NodeListOf<Element> | null | undefined = getAriaLabelledByElements(element);
|
||||
if (labels === null) {
|
||||
const ariaLabel = element.getAttribute('aria-label');
|
||||
if (ariaLabel !== null)
|
||||
return matcher({ full: ariaLabel, immediate: [ariaLabel] });
|
||||
}
|
||||
if (labels === null)
|
||||
labels = (element as HTMLInputElement).labels;
|
||||
return !!labels && [...labels].some(label => matcher(elementText(this._evaluator._cacheText, label)));
|
||||
|
@ -112,6 +112,16 @@ it('getByLabel should prioritize aria-labelledby over native label', async ({ pa
|
||||
expect(await page.getByLabel('Name').evaluate(e => e.textContent)).toBe('Click me');
|
||||
});
|
||||
|
||||
it('getByLabel should work with aria-label', async ({ page }) => {
|
||||
await page.setContent(`<input id=target aria-label="Name">`);
|
||||
expect(await page.getByLabel('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');
|
||||
});
|
||||
|
||||
it('getByPlaceholder should work', async ({ page }) => {
|
||||
await page.setContent(`<div>
|
||||
<input placeholder='Hello'>
|
||||
|
Loading…
Reference in New Issue
Block a user