Skip to main content

A page’s alert, confirm and prompt stop the page until they are answered, and a page script cannot keep them open for a client to answer later. So the plugin replaces them in the page (and in same-origin frames) with versions that answer at once and record the dialog. Paths follow http://127.0.0.1:4445/{token}; see the overview for the reply format and the errors.

Verified on macOS

On macOS a real app answered a confirm and a prompt (with the answer set before, and with the default dismiss), refused accepting a confirm that had been dismissed when it opened, saw an alert leave the answer to the confirm after it, and cleared the two in order.

How dialogs are answered#

The plugin replaces the dialogs whenever it is on (in debug builds by default), also while no test drives the app: the app’s dialogs then never show, and answer as below. A same-origin frame gets the replacements when the next command runs after the frame has loaded; a dialog it opens before that is the real one.

  • A confirm or prompt gets the answer the client set before it opened: POST /alert/accept or POST /alert/dismiss with no dialog recorded (the last one sent counts), and for a prompt POST /alert/text first for the text it returns. The first confirm or prompt uses that answer up; an alert needs none and leaves it for the next one. With no answer set, a confirm or prompt is dismissed (false, null), as W3C’s default dismiss would. A prompt accepted with no text set returns its default value (the second argument of prompt), or the empty string.
  • Every dialog is recorded, oldest first (the last 100 are kept), and GET /alert/text reads the oldest one’s message, or no such alert.
  • Accept or dismiss after a dialog opened clears the oldest record when it is the answer the page got (either one for an alert). The other one answers unsupported operation and keeps the record: the page already has its answer and cannot be given another. Sending text to a prompt that has opened answers unsupported operation, and to an alert or confirm element not interactable.
  • While a dialog is recorded, accept or dismiss handles it and sets no answer. So clear the dialogs a test does not care about (or check GET /alert/text) before setting the answer for the next one. An answer that no dialog used stays set for the next confirm or prompt, however much later; POST /alert/dismiss with no dialog recorded puts the default back.
  • Commands never fail with unexpected alert open. The dialogs and the answer are forgotten when the page loads another document and when a new session starts.

So a test that should accept a confirm accepts first, then clicks:

Accept a confirm
Warning

The usual WebDriver order, click and then accept (wait_for_and_accept_alert), gets unsupported operation for a confirm or prompt: it was dismissed when it opened, so the test fails there instead of going on as if it was accepted.

Get alert text#

GET /session/{sessionId}/alert/text

sessionIdstringrequired#

The current session’s id.

valuestringrequired#

The message of the oldest dialog recorded (the empty string for a dialog opened without one).

Errors

StatuserrorWhen
404no such alertNo dialog is recorded.

Accept alert#

POST /session/{sessionId}/alert/accept

With a dialog recorded: clears the oldest one, if it was accepted when it opened (any alert was). With none: sets accept as the answer for the next confirm or prompt, with the text sent before it, if any.

sessionIdstringrequired#

The current session’s id.

valuenullrequired#

null.

Errors

StatuserrorWhen
500unsupported operationThe oldest dialog is a confirm or prompt that was dismissed when it opened.

Dismiss alert#

POST /session/{sessionId}/alert/dismiss

With a dialog recorded: clears the oldest one, if it was dismissed when it opened (any alert can be). With none: sets dismiss as the answer for the next confirm or prompt, which puts the default back.

sessionIdstringrequired#

The current session’s id.

valuenullrequired#

null.

Errors

StatuserrorWhen
500unsupported operationThe oldest dialog is a confirm or prompt that was accepted when it opened.

Send alert text#

POST /session/{sessionId}/alert/text

With no dialog recorded: keeps the text for the answer that the next POST /alert/accept (or dismiss) sets, so the next prompt accepted returns it.

sessionIdstringrequired#

The current session’s id.

textstringrequired#

The text the next prompt returns.

valuenullrequired#

null.

Errors

StatuserrorWhen
400invalid argumenttext is missing or not a string.
400element not interactableThe oldest dialog recorded is an alert or a confirm (a confirm takes no text).
500unsupported operationThe oldest dialog recorded is a prompt: it was answered when it opened.