noPlaywrightElementHandle
Esta página aún no está disponible en tu idioma.
Summary
Section titled “Summary”- Rule available since:
v2.4.2 - Diagnostic Category:
lint/nursery/noPlaywrightElementHandle - This rule has an unsafe fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
- Same as
playwright/no-element-handle
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noPlaywrightElementHandle": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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();Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.