Class: Playwright::Dialog
- Inherits:
-
PlaywrightApi
- Object
- PlaywrightApi
- Playwright::Dialog
- 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, Playwright
def handle_dialog(dialog):
print(dialog.)
dialog.dismiss()
def run(playwright: 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
-
#accept(promptText: nil) ⇒ Object
Returns when the dialog has been accepted.
- #accept_async(promptText: nil) ⇒ Object
-
#default_value ⇒ Object
If dialog is prompt, returns default prompt value.
-
#dismiss ⇒ Object
Returns when the dialog has been dismissed.
-
#message ⇒ Object
A message displayed in the dialog.
-
#off(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#on(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#once(event, callback) ⇒ Object
– inherited from EventEmitter –.
-
#page ⇒ Object
The page that initiated this dialog, if available.
-
#type ⇒ Object
Returns dialog’s type, can be one of ‘alert`, `beforeunload`, `confirm` or `prompt`.
Methods inherited from PlaywrightApi
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
67 68 69 |
# File 'lib/playwright_api/dialog.rb', line 67 def accept_async(promptText: nil) wrap_impl(@impl.accept_async(promptText: unwrap_impl(promptText))) end |
#default_value ⇒ Object
If dialog is prompt, returns default prompt value. Otherwise, returns empty string.
38 39 40 |
# File 'lib/playwright_api/dialog.rb', line 38 def default_value wrap_impl(@impl.default_value) end |
#dismiss ⇒ Object
Returns when the dialog has been dismissed.
44 45 46 |
# File 'lib/playwright_api/dialog.rb', line 44 def dismiss wrap_impl(@impl.dismiss) end |
#message ⇒ Object
A message displayed in the dialog.
50 51 52 |
# File 'lib/playwright_api/dialog.rb', line 50 def wrap_impl(@impl.) end |
#off(event, callback) ⇒ Object
– inherited from EventEmitter –
79 80 81 |
# File 'lib/playwright_api/dialog.rb', line 79 def off(event, callback) event_emitter_proxy.off(event, callback) end |
#on(event, callback) ⇒ Object
– inherited from EventEmitter –
73 74 75 |
# File 'lib/playwright_api/dialog.rb', line 73 def on(event, callback) event_emitter_proxy.on(event, callback) end |
#once(event, callback) ⇒ Object
– inherited from EventEmitter –
85 86 87 |
# File 'lib/playwright_api/dialog.rb', line 85 def once(event, callback) event_emitter_proxy.once(event, callback) end |
#page ⇒ Object
The page that initiated this dialog, if available.
56 57 58 |
# File 'lib/playwright_api/dialog.rb', line 56 def page wrap_impl(@impl.page) end |
#type ⇒ Object
Returns dialog’s type, can be one of ‘alert`, `beforeunload`, `confirm` or `prompt`.
62 63 64 |
# File 'lib/playwright_api/dialog.rb', line 62 def type wrap_impl(@impl.type) end |