JS Testing Academy · QA Demo Site

Modal Dialogs

In-page modals – not browser alerts. They can be closed with the X, with a button, by clicking the background or with the Escape key.

Practice tasks

  1. Open the small modal, assert it is visible, close it with the Close button and assert it is hidden.
  2. Open it again and close it with the X, then with the Escape key.
  3. Open the small modal and close it by clicking the dark background.
  4. Open the large modal, scroll inside it and click Confirm; assert the log shows confirmed.
  5. Assert that the page behind the modal cannot be clicked while it is open.
Sample automation code
driver.findElement(By.id("show-small-modal")).click();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("small-modal-text")));

driver.findElement(By.id("close-small-modal")).click();
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("small-modal-text")));