Dialogs
Playwright can interact with the web page dialogs such as alert
, confirm
, prompt
as well as beforeunload
confirmation.
#
alert(), confirm(), prompt() dialogsYou can register a dialog handler before the action that triggers the dialog to accept or decline it.
note
If your action, be it page.click(selector[, options]), page.evaluate(pageFunction[, arg]) or any other, results in a dialog, the action will stall until the dialog is handled. That's because dialogs in Web are modal and block further page execution until they are handled.
As a result, following snippet will never resolve:
:::warn WRONG! :::
:::warn WRONG! :::
#
API reference#
beforeunload dialogWhen page.close([options]) is invoked with the truthy runBeforeUnload
value, it page runs its unload handlers. This is the only case when page.close([options]) does not wait for the page to actually close, because it might be that the page stays open in the end of the operation.
You can register a dialog handler to handle the beforeunload dialog yourself: