Playwright: How can i accept this pop up?

Created on 29 Apr 2020  路  2Comments  路  Source: microsoft/playwright

image
I tried

 page.on('popup', async dialog => {
        console.log(dialog.message());
        await dialog.dismiss();
        await browser.close();
    });

and also

page.on('dialog', async dialog => { console.log(dialog.message()); await dialog.dismiss(); await browser.close(); });
But both did not help me

Most helpful comment

The second code bock is what should be working.
Are you adding your page bindings prior the the dialog being triggered?

Here is an example I tried that works as expected.

import playwright from 'playwright';

(async () => {
  const browser = await playwright.chromium.launch({
    headless: false,
    slowMo: 500
  });
  const context1 = await browser.newContext();
  const page1 = await context1.newPage();
  await page1.goto('https://google.com');
  page1.on('dialog', async (dialog) => {
    console.log(dialog.message());
    await dialog.accept();
  });
  await page1.evaluate(() => {
    confirm('are you sure');
  });
  await context1.close();
  browser.close();
})();

All 2 comments

The second code bock is what should be working.
Are you adding your page bindings prior the the dialog being triggered?

Here is an example I tried that works as expected.

import playwright from 'playwright';

(async () => {
  const browser = await playwright.chromium.launch({
    headless: false,
    slowMo: 500
  });
  const context1 = await browser.newContext();
  const page1 = await context1.newPage();
  await page1.goto('https://google.com');
  page1.on('dialog', async (dialog) => {
    console.log(dialog.message());
    await dialog.accept();
  });
  await page1.evaluate(() => {
    confirm('are you sure');
  });
  await context1.close();
  browser.close();
})();

Thanks @nrayburn-tech.

Was this page helpful?
0 / 5 - 0 ratings