admin管理员组

文章数量:1202779

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

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
Share Improve this question asked May 15, 2018 at 14:20 Gilles QuénotGilles Quénot 185k43 gold badges231 silver badges229 bronze badges 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
Add a comment  | 

1 Answer 1

Reset to default 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

本文标签: javascriptIs it possible to simulate pressing 39Down39 arrowStack Overflow