Testing / Playwright Interview questions
What are locators in Playwright?
A locator represents a way to find one or more elements on the page at any given moment - it's a strategy, not a snapshot. Creating a locator doesn't query the DOM immediately; the query only runs when an action like .click() or an assertion is actually performed.
const button = page.getByRole('button', { name: 'Submit' }); await button.click();
Because the query re-runs at action time, locators automatically pick up elements that appear later or get re-rendered, and they auto-retry until the actionability checks pass or the timeout expires. This is the key difference from the older ElementHandle, which captures a fixed reference to a DOM node that can go stale.
More Related questions...