Puppeteer 对话

2020-06-29 14:20 更新

class:dialog

class: Dialog v0.9.0 Dialog 对象通过 'dialog' 事件的页面分发。 一个使用 Dialog 类的例子:

const puppeteer = require('puppeteer');
puppeteer.launch().then(async browser = >{
    const page = await browser.newPage();
    page.on('dialog', async dialog = >{
        console.log(dialog.message());
        await dialog.dismiss();
        await browser.close();
    });
    page.evaluate(() = >alert('1'));
});

Methods

  • dialog.accept([promptText])v0.9.0
  • dialog.defaultValue()v0.9.0
  • dialog.dismiss()v0.9.0
  • dialog.message()v0.9.0
  • dialog.type()v0.9.0

Methods

dialog.accept([promptText])v0.9.0

  • promptText <string> 提示中输入的文本。 如果对话框的类型不提示,不会产生任何影响。
  • returns: <Promise> Promise which resolves when the dialog has been accepted.

dialog.defaultValue()v0.9.0

  • returns: <string> 如果对话框出现提示,则返回默认提示值。 否则,返回空字符串。

dialog.dismiss()v0.9.0

  • returns: <Promise> Promise which resolves when the dialog has been dismissed.

dialog.message()v0.9.0

  • returns: <string> 显示在对话框中的信息。

dialog.type()v0.9.0

  • returns: <string> 对话框类型,可以是 alert ,beforeunload ,confirm 或 prompt 中的一个。
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号