Selenium WebDriver 4

Accept a JavaScript alert

Medium70 pts~25 min
  • Alerts
  • switchTo
Practice app · UI Widgets Lab

Native alerts, confirm and prompt dialogs, a modal, a cookie banner, custom dropdown, autocomplete, date picker and tooltip.

Test URL
/lab/selenium-accept-a-javascript-alert

Your starter code already declares TEST_URL — never hardcode a host.

Objective

Trigger a native alert, switch to it and accept it.

Your task

  1. 1Open TEST_URL and click #alert-button.
  2. 2Wait for the alert, switch to it and accept it.
  3. 3Assert #alert-result shows “Alert accepted”.

Acceptance criteria

  • The test switches to the alert
  • The alert is accepted
  • #alert-result shows “Alert accepted”
  • At least 1 assertion passes

Selenium WebDriver 4 · Selenium · Dropdowns, alerts & popups