noPlaywrightWaitForSelector
Summary
Section titled “Summary”- Rule available since:
v2.4.2 - Diagnostic Category:
lint/nursery/noPlaywrightWaitForSelector - 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-wait-for-selector
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noPlaywrightWaitForSelector": "error" } } }}Description
Section titled “Description”Disallow using page.waitForSelector().
Playwright’s page.waitForSelector() is discouraged in favor of more reliable locator-based APIs.
Using locators with assertions or actions automatically waits for elements to be ready.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”await page.waitForSelector('.submit-button');code-block.js:1:7 lint/nursery/noPlaywrightWaitForSelector FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Unexpected use of page.waitForSelector().
> 1 │ await page.waitForSelector(‘.submit-button’);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Locators automatically wait for elements to be ready, making explicit waits unnecessary.
ℹ Use locator-based page.locator() or page.getByRole() APIs 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(selector).waitFor().
1 │ - await·page.waitForSelector(‘.submit-button’);
1 │ + await·page.locator(‘.submit-button’).waitFor();
2 2 │
await page.waitForSelector('#dialog', { state: 'visible' });await page.click('#dialog .button');code-block.js:1:7 lint/nursery/noPlaywrightWaitForSelector FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Unexpected use of page.waitForSelector().
> 1 │ await page.waitForSelector(‘#dialog’, { state: ‘visible’ });
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │ await page.click(‘#dialog .button’);
3 │
ℹ Locators automatically wait for elements to be ready, making explicit waits unnecessary.
ℹ Use locator-based page.locator() or page.getByRole() APIs 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(selector).waitFor().
1 │ - await·page.waitForSelector(‘#dialog’,·{·state:·‘visible’·});
1 │ + await·page.locator(‘#dialog’).waitFor({·state:·‘visible’·});
2 2 │ await page.click(‘#dialog .button’);
3 3 │
await page.locator('.submit-button').click();await expect(page.locator('#dialog')).toBeVisible();const button = page.getByRole('button', { name: 'Submit' });await button.click();Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.