How to fix Playwright "Element is not attached to the DOM"?
PlaywrightThe element was re-rendered between lookup and action, so the handle became stale.
Prefer locators (auto-retry) instead of storing ElementHandle values.
const saveButton = page.getByRole('button', { name: 'Save' });
await expect(saveButton).toBeVisible();
await saveButton.click();
Common mistake: querying once with $ and clicking later after UI updates.