How to fix Playwright "strict mode violation" locator errors?

Playwright

strict mode violation means your locator matches multiple elements, but the action needs exactly one.

Narrow the locator with role/name filters, scoping, or .first() only when order is stable.

const dialog = page.getByRole('dialog', { name: 'Delete project' });
await dialog.getByRole('button', { name: 'Delete' }).click();

Avoid broad selectors like .btn for click actions in larger pages.