
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
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.
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.