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:
“‘js const { chromium } = require(’playwright’); // Or ‘firefox’ or ‘webkit’.
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
page.on('dialog', async dialog => {
console.log(dialog.());
await dialog.dismiss();
await browser.close();
});
page.evaluate(() => alert('1'));
})(); “‘
“‘python async import asyncio from playwright.async_api import async_playwright
async def handle_dialog(dialog):
print(dialog.)
await dialog.dismiss()
async def run(playwright):
chromium = playwright.chromium
browser = await chromium.launch()
page = await browser.new_page()
page.on("dialog", handle_dialog)
page.evaluate("alert('1')")
await browser.close()
async def main():
async with async_playwright() as playwright:
await run(playwright)
asyncio.run(main()) “‘
“‘python sync # FIXME from playwright.sync_api import sync_playwright
def handle_dialog(dialog):
print(dialog.)
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)
“‘
Instance Method Summary collapse
-
#accept(promptText: nil) ⇒ Object
Returns when the dialog has been accepted.
-
#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.
-
#type_text ⇒ Object
Returns dialog’s type, can be one of
alert,beforeunload,confirmorprompt.
Methods inherited from PlaywrightApi
#==, from_channel_owner, #initialize
Constructor Details
This class inherits a constructor from Playwright::PlaywrightApi
Instance Method Details
#accept(promptText: nil) ⇒ Object
Returns when the dialog has been accepted.
66 67 68 |
# File 'lib/playwright_api/dialog.rb', line 66 def accept(promptText: nil) raise NotImplementedError.new('accept is not implemented yet.') end |
#default_value ⇒ Object
If dialog is prompt, returns default prompt value. Otherwise, returns empty string.
71 72 73 |
# File 'lib/playwright_api/dialog.rb', line 71 def default_value raise NotImplementedError.new('default_value is not implemented yet.') end |
#dismiss ⇒ Object
Returns when the dialog has been dismissed.
76 77 78 |
# File 'lib/playwright_api/dialog.rb', line 76 def dismiss raise NotImplementedError.new('dismiss is not implemented yet.') end |
#message ⇒ Object
A message displayed in the dialog.
81 82 83 |
# File 'lib/playwright_api/dialog.rb', line 81 def raise NotImplementedError.new('message is not implemented yet.') end |
#type_text ⇒ Object
Returns dialog’s type, can be one of alert, beforeunload, confirm or prompt.
86 87 88 |
# File 'lib/playwright_api/dialog.rb', line 86 def type_text raise NotImplementedError.new('type_text is not implemented yet.') end |