javascriptpuppeteergoogle-chrome-headless

Is it possible to simulate pressing 'Down' arrow?


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

Solution

  • 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