Search code examples
javascriptnode.jsweb-scrapingautomationpuppeteer

Puppeteer Press Enter Button or Click Dialog OK Button


OK button dialog

I'm at the end of a Puppeteer script. I just need to click the OK button on the confirm dialog box (see link to image) or press the enter key. For pressing the enter key I tried every suggestion here Pressing Enter button in puppeteer and nothing worked. I checked with a normal browser and pressing the enter key works. Any suggestions?

Problem solved thanks to Thomas! See solution below.


Solution

  • This is a confirm dialog. Have a look at dialog handling.

    You can press the OK button like this:

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

    Put the code in front of the action that triggers the dialog (otherwise the event handler will not be registered when the dialog event is fired).