8

I try to figure out how to send Down in , I tried with the int code 40 or Down string, but none works.

Is there a proper way ? Can't figure it out after reading ~/node_modules/puppeteer/lib/Input.js

const elementHandle = await page.$('selector');
await elementHandle.type('something');
await page.keyboard.press(40); // fail
1
  • Can you go into more detail about how it doesn't work? Are you expecting it cause the browser to scroll down? Typically, manually triggered events don't cause default user agent actions due to security concerns. I'm not sure if this is the case for puppeteer as well. What are you expecting to happen.
    – zero298
    Commented May 15, 2018 at 14:24

1 Answer 1

23

You need to use 'ArrowDown'.

The keyboard.press functions wants a string as name of the key. https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#keyboardpresskey-options

So the line to press the down arrow would be:

await page.keyboard.press('ArrowDown');

Here is the list of available keys: https://github.com/puppeteer/puppeteer/blob/main/packages/puppeteer-core/src/common/USKeyboardLayout.ts

2
  • 2
    This does not work on a select in MacOS
    – Roel
    Commented Jul 13, 2022 at 9:25
  • @Roel I don't have any way to test that, but I think that would be an issue to create on the Puppeteer repository.
    – Seblor
    Commented Jul 13, 2022 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.