Skip to content
SDETRole
SDETRole

Handle confirm and prompt dialogs

intermediate Alerts Challenge 11 of 13

The drafts page uses native browser dialogs. Clicking Delete (#delete-draft) opens a confirm("Delete this draft?"), and clicking Rename (#rename-draft) opens a prompt("New name for this draft:"). The current test sleeps and never touches the dialogs, so it fails with UnhandledAlertException.

Requirements

  • Remove every Thread.sleep.
  • After each click, wait with ExpectedConditions.alertIsPresent() and get the dialog with driver.switchTo().alert().
  • Assert the confirm’s text, then dismiss it so the draft is kept.
  • Assert the prompt’s text, type Q3 regression plan into it and accept it.
  • Finally assert that #draft-title shows the new name.

Expected output

Each click is followed by `wait.until(ExpectedConditions.alertIsPresent())` and `driver.switchTo().alert()`. The confirm's text is asserted and the confirm is dismissed; the prompt's text is asserted, it receives `sendKeys("Q3 regression plan")` and is accepted. There is no `Thread.sleep`.

Checks (6)

  • ○No Thread.sleep
  • ○Waits for the dialog with ExpectedConditions.alertIsPresent()
  • ○Switches to the dialog with driver.switchTo().alert()
  • ○Dismisses (cancels) the confirm
  • ○Types into the prompt and then accepts it
  • ○Reads the dialog text
Solution.javaValidated · not executed

Ctrl/⌘ + Enter to validate · your code is saved in this browser

Results

Validate your code against the checks.

Type to search across SDETRole.

Full-text search by Pagefind · runs in your browser Open search page →