Testing / Playwright Interview questions
How do you handle elements that load dynamically or asynchronously?
Because locators are lazy and auto-retrying, the usual recommendation is simply to act on the locator directly rather than manually polling for the element first.
// No manual wait needed - the locator retries internally await page.getByText('Results loaded').waitFor(); await page.getByRole('row').first().click();
For content that appears after an async data fetch, chaining an assertion like expect(locator).toBeVisible() before interacting gives a clear, self-documenting wait point. When a whole list re-renders with new item counts, expect(locator).toHaveCount(n) is more robust than trying to time a fixed delay. Explicit waitForResponse() can also be used to wait for the specific network call that populates the dynamic content, which is more precise than waiting on the UI alone when the timing is critical.
More Related questions...