Search code examples
javascriptnode.jsautomationautomated-testspuppeteer

How to click JavaScript prompt using puppeteer


Let's say I visit some website and then a popup comes, asking to allow my video. How do I select and make it true?

I tried the await page.keyboard.press('Enter') but it doesn't work.


Solution

  • You need to create an event listener for dialogs:

    page.on('dialog', async dialog => {
        await dialog.accept();
    });
    

    You can read the full documentation here.