Testing / Playwright Interview questions
What is the difference between waitForSelector and waitForLoadState?
These wait for two different things, and confusing them is a common source of either flaky or unnecessarily slow tests.
| waitForSelector | waitForLoadState |
| Waits for a specific element to reach a state (attached/visible) | Waits for the page as a whole to reach a load milestone |
| Element-scoped | Page-scoped |
| Largely superseded by auto-waiting locators | Still commonly used after navigation or SPA route changes |
page.waitForSelector() is mostly legacy now, since modern locators auto-wait for the same conditions implicitly. page.waitForLoadState('networkidle') is still genuinely useful, though, for cases like waiting for a single-page app to finish its post-navigation data fetching before interacting with content that only appears afterward.
More Related questions...