Dialog
Dialog objects are dispatched by page via the [event: Page.dialog
] event.
An example of using Dialog class:
def handle_dialog(dialog)
puts "[#{dialog.type}] #{dialog.message}"
if dialog.message =~ /foo/
dialog.accept
else
dialog.dismiss
end
end
page.on("dialog", method(:handle_dialog))
page.evaluate("confirm('foo')") # will be accepted
# => [confirm] foo
page.evaluate("alert('bar')") # will be dismissed
# => [alert] bar
NOTE: Dialogs are dismissed automatically, unless there is a [event: Page.dialog
] listener.
When listener is present, it must either Dialog#accept or Dialog#dismiss the dialog - otherwise the page will freeze waiting for the dialog, and actions like click will never finish.
accept
def accept(promptText: nil)
Returns when the dialog has been accepted.