How should Playwright handle a locator when the UI changes but the user flow stays the same?
12:10 27 Aug 2026

I’m exploring Playwright test maintenance and came across a situation I’m curious about.

Suppose a test originally uses:

await page.getByRole('button', { name: 'Submit' }).click();

Later, the UI is updated and the button text changes from Submit to Continue, while the underlying user action remains the same.

The original locator now fails, even though the functionality being tested may not have changed.

Updating the locator to match the new UI is straightforward. The difficult part is determining whether the new element is actually the intended replacement.

For example, if there are multiple similar elements on the page, simply choosing another matching element could make the test pass while it is actually interacting with the wrong element.

How do you handle this situation in Playwright?

advice typescript testing automated-tests playwright