mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
parent
3ad65e7ce8
commit
24f2ccb4ca
@ -298,6 +298,11 @@ export class InjectedScript {
|
|||||||
const allElements = this._evaluator._queryCSS({ scope: root as Document | Element, pierceShadow: true }, '*');
|
const allElements = this._evaluator._queryCSS({ scope: root as Document | Element, pierceShadow: true }, '*');
|
||||||
return allElements.filter(element => {
|
return allElements.filter(element => {
|
||||||
let labels: Element[] | NodeListOf<Element> | null | undefined = getAriaLabelledByElements(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)
|
if (labels === null)
|
||||||
labels = (element as HTMLInputElement).labels;
|
labels = (element as HTMLInputElement).labels;
|
||||||
return !!labels && [...labels].some(label => matcher(elementText(this._evaluator._cacheText, label)));
|
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');
|
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 }) => {
|
it('getByPlaceholder should work', async ({ page }) => {
|
||||||
await page.setContent(`<div>
|
await page.setContent(`<div>
|
||||||
<input placeholder='Hello'>
|
<input placeholder='Hello'>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user