Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to simulate pressing 'Down' arrow?

I try to figure out how to send Down in puppeteer, 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
like image 661
Gilles Quenot Avatar asked May 15 '18 14:05

Gilles Quenot


1 Answers

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/src/common/USKeyboardLayout.ts

like image 100
Seblor Avatar answered Oct 05 '22 13:10

Seblor