Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 798
Greg Avatar asked Jan 01 '23 23:01

Greg


1 Answers

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

like image 117
Thomas Dondorf Avatar answered Jan 05 '23 07:01

Thomas Dondorf