Pressing Enter button in puppeteer

Pressing enter in puppeteer doesn't seem to have any effect. However, when I press other keys, it does what it should. This works:


This doesn't:


This is how the input looks like:

Any ideas?

EDIT: I've also tried page.keyboard.down & page.keyboard.up to be sure.


await page.type(String.fromCharCode(13));

Using this site I noticed that page.type dispatches beforeinput and input events, but doesn't. This is probably a bug, but fortunately sending the enter keycode (13) seems to work, so we can work around it for now.

I've used'Enter'); usually :) Works for me.

Have a look at the documentation here. I think you should use .keyboard before .press for it to work properly.

You can use to simulate pressing the enter key. Any of the following options should work:

await'Enter'); // Enter Key
await'NumpadEnter'); // Numeric Keypad Enter Key
await'\n'); // Shortcut for Enter Key
await'\r'); // Shortcut for Enter Key

Additionally, you can use use a combination of page.$() and to focus on an element before pressing enter:

await (await page.$('input[type="text"]')).press('Enter'); // Enter Key
await (await page.$('input[type="text"]')).press('NumpadEnter'); // Numeric Keypad Enter Key
await (await page.$('input[type="text"]')).press('\n'); // Shortcut for Enter Key
await (await page.$('input[type="text"]')).press('\r'); // Shortcut for Enter Key

Furthermore, you can use page.type():

await page.type(String.fromCharCode(13));

Likewise, you can use page.keyboard.type():

await page.keyboard.type(String.fromCharCode(13));

Another alternative method would be to use the page.keyboard.sendCharacter() method:

await page.keyboard.sendCharacter(String.fromCharCode(13));
page.keyboard.down() / page.keyboard.up():

You can also use a combination of page.keyboard.down() and page.keyboard.up():

// Enter Key
await page.keyboard.down('Enter');
await page.keyboard.up('Enter');

// Shortcut for Enter Key
await page.keyboard.down('NumpadEnter');
await page.keyboard.up('NumpadEnter');

// Shortcut for Enter Key
await page.keyboard.down('\n');
await page.keyboard.up('\n');

// Shortcut for Enter Key
await page.keyboard.down('\r');
await page.keyboard.up('\r');

Need Your Help

How to randomize a vector

r vector random shuffle

I would like to randomly reorganize the order of the numbers in a vector, in a simple one-line command?

AngularJS - Set default value on select inside a ng-repeat

javascript angularjs select angularjs-ng-repeat

I'm facing to an issue with AngularJS - I'm not able to display the selected value in a <select>.