Przejdź do głównej zawartości

noPlaywrightElementHandle

Ta treść nie jest jeszcze dostępna w Twoim języku.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noPlaywrightElementHandle": "error"
}
}
}
}

Disallow usage of element handles (page.$() and page.$$()).

Element handles are discouraged in Playwright. Use locators instead, which auto-wait and are more reliable. Locators represent a way to find elements at any moment, while element handles are references to specific elements that may become stale.

const button = await page.$('button');
code-block.js:1:22 lint/nursery/noPlaywrightElementHandle  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of element handles.

> 1 │ const button = await page.$(‘button’);
^^^^^^^^^^^^^^^^
2 │

Locators auto-wait and are more reliable than element handles, which can become stale.

Use page.locator() or getByRole() instead.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Replace $() with locator().

1 - const·button·=·await·page.$(button);
1+ const·button·=·await·page.locator(button);
2 2

const buttons = await page.$$('.btn');
code-block.js:1:23 lint/nursery/noPlaywrightElementHandle  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of element handles.

> 1 │ const buttons = await page.$$(‘.btn’);
^^^^^^^^^^^^^^^
2 │

Locators auto-wait and are more reliable than element handles, which can become stale.

Use page.locator() or getByRole() instead.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Replace $$() with locator().

1 - const·buttons·=·await·page.$$(.btn);
1+ const·buttons·=·await·page.locator(.btn);
2 2

const element = await frame.$('#element');
code-block.js:1:23 lint/nursery/noPlaywrightElementHandle  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected use of element handles.

> 1 │ const element = await frame.$(‘#element’);
^^^^^^^^^^^^^^^^^^^
2 │

Locators auto-wait and are more reliable than element handles, which can become stale.

Use frame.locator() or getByRole() instead.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Replace $() with locator().

1 - const·element·=·await·frame.$(#element);
1+ const·element·=·await·frame.locator(#element);
2 2

const button = page.locator('button');
await button.click();
const buttons = page.locator('.btn');
await expect(buttons).toHaveCount(3);
await page.getByRole('button', { name: 'Submit' }).click();