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:

“‘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.message());
  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.message)
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.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)

“‘

Instance Method Summary collapse

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.

Raises:

  • (NotImplementedError)


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_valueObject

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

Raises:

  • (NotImplementedError)


71
72
73
# File 'lib/playwright_api/dialog.rb', line 71

def default_value
  raise NotImplementedError.new('default_value is not implemented yet.')
end

#dismissObject

Returns when the dialog has been dismissed.

Raises:

  • (NotImplementedError)


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

def dismiss
  raise NotImplementedError.new('dismiss is not implemented yet.')
end

#messageObject

A message displayed in the dialog.

Raises:

  • (NotImplementedError)


81
82
83
# File 'lib/playwright_api/dialog.rb', line 81

def message
  raise NotImplementedError.new('message is not implemented yet.')
end

#typeObject

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

Raises:

  • (NotImplementedError)


86
87
88
# File 'lib/playwright_api/dialog.rb', line 86

def type
  raise NotImplementedError.new('type is not implemented yet.')
end