4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Puppeteerでdialog OK後のdialogを捕捉

Last updated at Posted at 2018-03-06

動作検証環境

Puppeteer 1.1.1

コード

const puppeteer = require('puppeteer');
const assert = require('assert');
(async () => {
// 中略
    await page.once('dialog', async dialog => {
        console.log(dialog.message());
        assert.equal(dialog.message(), '一回目だよ')

        // OK後のアラートを設定
        await page.once('dialog', async dialog => {
            console.log(dialog.message());
            assert.equal(dialog.message(), '二回目だよ')
            await dialog.accept();
        })

        await dialog.accept();
    });
    await page.click('#ダイアログを起こすclickイベントがある要素');
})();

ダメな例

await page.once(/**/);
await page.click(/**/);
await page.once(/**/);

実行速度にもよるだろうが、最初のdialogに両方のイベントが引っ掛かった。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?