Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
Python interview question
Browser automationMiddleVery commonPractical

How do Playwright's locators and auto-waiting change the way you write Python UI tests compared with Selenium-style explicit waits?

Answer

A Playwright locator is re-resolved when it is used and participates in retryable actions and assertions. Before an action such as click, Playwright waits for relevant actionability conditions such as visibility, stability, event reception and enabled state; web-first assertions retry until their condition is met. Prefer user-facing locators such as role, label or test id over brittle DOM chains, and do not replace Playwright's waiting model with `time.sleep()` or arbitrary timeouts unless diagnosing a specific problem.

Strong answer includes

  • explains locator re-resolution and actionability rather than saying only that Playwright waits automatically
  • prefers semantic user-facing locators over brittle CSS or XPath structure
  • uses retrying assertions and avoids fixed sleeps as normal synchronization

Practical example

For a Save button,

Python example
page.get_by_role("button", name="Save").click()

lets Playwright wait until that single button is actionable. A following

Python example
expect(page.get_by_text("Saved")).to_be_visible()

retries the assertion; adding

Python example
time.sleep(2)

between the two usually makes the test slower and less deterministic.

#playwright#locators#auto-waiting#ui-automation

Sources

Playwright for Python documentationMicrosoft Playwright · Authoritative Python behavior for locators, auto-waiting, browser contexts, network controls and test isolationPlaywright Interview Questions for SDET 2026AI Test Automation Hub · 2026 interview signal for Playwright auto-waiting, semantic locators, browser contexts, network interception and debuggingPlaywright Interview Questions and Answers (2026 Guide)The Testing Academy · 2026 recurrence signal for Playwright locators, auto-waiting, fixtures, network interception and hands-on debuggingThe Complete 2026 SDET Interview Preparation GuideScrollTest · 2026 interview signal for Selenium dynamic elements, Playwright, framework design, test data and CI-oriented automation