Playwright Basics
Beginner course
Practice interacting with, asserting, and closing modal dialogs and overlays in your test suites.
Interactive Scenarios
Beginner course
Hard course
| ID | Scenario | Type | Priority | |
|---|---|---|---|---|
| MDL_001 | Simple modal can be opened Expected: Modal dialog becomes visible on screen โ
positivehigh | positive | high | |
| MDL_002 | Simple modal can be closed Expected: Modal dialog is removed from screen and result updates โ
positivehigh | positive | high | |
| MDL_003 | Scoped modal from card can be opened Expected: Correct modal tied to the card becomes visible โ
positivehigh | positive | high | |
| MDL_004 | Scoped modal from card can be closed Expected: Modal is closed and result updates โ
positivemedium | positive | medium | |
| MDL_005 | Dynamic ID modal can be confirmed Expected: Confirm button is successfully located and clicked โ
positivemedium | positive | medium | |
| MDL_006 | Missing locator modal can be accepted via ARIA Expected: Accept button is successfully located without a test id โ
positivehigh | positive | high | |
| MDL_007 | Modal background overlay exists Expected: Overlay prevents interaction with background elements โ ๏ธ edgelow | edge | low | |
| MDL_008 | Modal can be closed by clicking outside Expected: Clicking the backdrop closes the modal โ ๏ธ edgemedium | edge | medium |
Modal windows (or dialogs) overlay the main content, demanding user attention. Automating them requires locating the newly active DOM elements, often relying on ARIA roles or specific container classes.
Modern frameworks handle modals well, but you should explicitly wait for or locate the modal container to ensure it has fully rendered before interacting with its contents.
const modal = page.getByRole('dialog');
await expect(modal).toBeVisible();Once the modal is visible, scope your locators to the modal container to prevent accidentally interacting with elements in the background page.
await modal.getByRole('button', { name: 'Confirm' }).click();
await expect(modal).toBeHidden();| Action | Selenium | Playwright JS | Playwright PY | Cypress |
|---|---|---|---|---|
| Locate Modal | driver.findElement() | page.getByRole('dialog') | page.get_by_role('dialog') | cy.get('.modal') |
| Scope Element | modal.findElement() | modal.getByRole() | modal.get_by_role() | cy.get('.modal').find() |