Use case
Wait For Alert and Wait For Alerts can already verify a dialog's text, but they cannot verify which kind of dialog fired. A page can show either a confirm() or a prompt() depending on state, and a regression that swaps one for the other (or that suddenly shows a plain alert() instead of a confirmation) currently passes silently as long as the text happens to match — and if the texts are identical or empty, there is no way at all to tell the dialogs apart. Playwright knows the type of every dialog (alert, confirm, prompt, beforeunload), but the library never surfaces it, and there is no workaround because dialogs cannot be inspected by any other keyword.
Asserting the type alongside the text is a natural extension of the same keyword that already returns the message text.
Proposed keyword / arguments
New named-only argument on Wait For Alert:
expected_type: DialogType | None = None — one of alert, confirm, prompt, beforeunload. When given, the keyword fails if the handled dialog's type differs. Default None skips the check (current behavior).
Matching new argument on Wait For Alerts:
types: list[DialogType | None] | None = None — one entry per expected dialog, None entries skip the check for that dialog. Default None disables type checking entirely (current behavior). When given, the list length must match actions/prompt_inputs/texts, consistent with the existing validation.
${promise} = Promise To Wait For Alert action=accept text=Delete this item? expected_type=confirm
Click id=delete
${text} = Wait For ${promise}
# Two dialogs: first must be a confirm, second a prompt
${promise} = Promise To Wait For Alerts
... ["accept", "accept"]
... [None, "my input"]
... [None, None]
... types=["confirm", "prompt"]
Click id=confirmAndPrompt
${texts} = Wait For ${promise}
Playwright API
Maps to dialog.type(), which returns one of alert, beforeunload, confirm or prompt. The dialog object is already handled inside the wrapper's waitForAlerts implementation; its type just needs to be read and checked.
Implementation notes
protobuf/playwright.proto: extend the AlertAction message with an optional expected type field.
node/playwright-wrapper: in the dialog handler, compare dialog.type() against the expected type (when set) and reject with a clear error message on mismatch.
Browser/keywords/interaction.py: add expected_type to wait_for_alert and types to wait_for_alerts (with the same length validation as the existing lists), plus a DialogType enum in Browser/utils/data_types.py if none fits.
- Docs and atest: the test app already triggers alert/confirm/prompt dialogs.
Backwards compatibility
Purely additive: both arguments default to None, which skips type verification entirely, so all existing suites behave exactly as before.
Use case
Wait For AlertandWait For Alertscan already verify a dialog's text, but they cannot verify which kind of dialog fired. A page can show either aconfirm()or aprompt()depending on state, and a regression that swaps one for the other (or that suddenly shows a plainalert()instead of a confirmation) currently passes silently as long as the text happens to match — and if the texts are identical or empty, there is no way at all to tell the dialogs apart. Playwright knows the type of every dialog (alert,confirm,prompt,beforeunload), but the library never surfaces it, and there is no workaround because dialogs cannot be inspected by any other keyword.Asserting the type alongside the text is a natural extension of the same keyword that already returns the message text.
Proposed keyword / arguments
New named-only argument on
Wait For Alert:expected_type: DialogType | None = None— one ofalert,confirm,prompt,beforeunload. When given, the keyword fails if the handled dialog's type differs. DefaultNoneskips the check (current behavior).Matching new argument on
Wait For Alerts:types: list[DialogType | None] | None = None— one entry per expected dialog,Noneentries skip the check for that dialog. DefaultNonedisables type checking entirely (current behavior). When given, the list length must matchactions/prompt_inputs/texts, consistent with the existing validation.Playwright API
Maps to
dialog.type(), which returns one ofalert,beforeunload,confirmorprompt. The dialog object is already handled inside the wrapper'swaitForAlertsimplementation; its type just needs to be read and checked.Implementation notes
protobuf/playwright.proto: extend theAlertActionmessage with an optional expected type field.node/playwright-wrapper: in the dialog handler, comparedialog.type()against the expected type (when set) and reject with a clear error message on mismatch.Browser/keywords/interaction.py: addexpected_typetowait_for_alertandtypestowait_for_alerts(with the same length validation as the existing lists), plus aDialogTypeenum inBrowser/utils/data_types.pyif none fits.Backwards compatibility
Purely additive: both arguments default to
None, which skips type verification entirely, so all existing suites behave exactly as before.