Class: Playwright::Dialog

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/dialog.rb

Overview

‘Dialog` objects are dispatched by page via the [`event: Page.dialog`] event.

An example of using ‘Dialog` class:

“‘python sync from playwright.sync_api import sync_playwright

def handle_dialog(dialog):

print(dialog.message)
dialog.dismiss()

def run(playwright):

chromium = playwright.chromium
browser = chromium.launch()
page = browser.new_page()
page.on("dialog", handle_dialog)
page.evaluate("alert('1')")
browser.close()

with sync_playwright() as playwright:

run(playwright)

“‘

> NOTE: Dialogs are dismissed automatically, unless there is a [‘event: Page.dialog`] listener. When listener is present, it must either [`method: Dialog.accept`] or [`method: Dialog.dismiss`] the dialog - otherwise the page will [freeze](developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and actions like click will never finish.

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#accept(promptText: nil) ⇒ Object

Returns when the dialog has been accepted.



32
33
34
# File 'lib/playwright_api/dialog.rb', line 32

def accept(promptText: nil)
  wrap_impl(@impl.accept(promptText: unwrap_impl(promptText)))
end

#accept_async(promptText: nil) ⇒ Object



57
58
59
# File 'lib/playwright_api/dialog.rb', line 57

def accept_async(promptText: nil)
  wrap_impl(@impl.accept_async(promptText: unwrap_impl(promptText)))
end

#default_valueObject

If dialog is prompt, returns default prompt value. Otherwise, returns empty string.



37
38
39
# File 'lib/playwright_api/dialog.rb', line 37

def default_value
  wrap_impl(@impl.default_value)
end

#dismissObject

Returns when the dialog has been dismissed.



42
43
44
# File 'lib/playwright_api/dialog.rb', line 42

def dismiss
  wrap_impl(@impl.dismiss)
end

#messageObject

A message displayed in the dialog.



47
48
49
# File 'lib/playwright_api/dialog.rb', line 47

def message
  wrap_impl(@impl.message)
end

#off(event, callback) ⇒ Object

– inherited from EventEmitter –



63
64
65
# File 'lib/playwright_api/dialog.rb', line 63

def off(event, callback)
  event_emitter_proxy.off(event, callback)
end

#on(event, callback) ⇒ Object

– inherited from EventEmitter –



75
76
77
# File 'lib/playwright_api/dialog.rb', line 75

def on(event, callback)
  event_emitter_proxy.on(event, callback)
end

#once(event, callback) ⇒ Object

– inherited from EventEmitter –



69
70
71
# File 'lib/playwright_api/dialog.rb', line 69

def once(event, callback)
  event_emitter_proxy.once(event, callback)
end

#typeObject

Returns dialog’s type, can be one of ‘alert`, `beforeunload`, `confirm` or `prompt`.



52
53
54
# File 'lib/playwright_api/dialog.rb', line 52

def type
  wrap_impl(@impl.type)
end