是否可以模拟按下 'Down' 箭头?

Is it possible to simulate pressing 'Down' arrow?

我试图弄清楚如何在 中发送 Down,我尝试使用 int 代码 40Down 字符串,但是 none 有效。

有什么好的方法吗?看不懂~/node_modules/puppeteer/lib/Input.js

const elementHandle = await page.$('selector');
await elementHandle.type('something');
await page.keyboard.press(40); // fail

您需要使用'ArrowDown'

keyboard.press 函数需要一个字符串作为键的 namehttps://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#keyboardpresskey-options

因此按下向下箭头的行将是:

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

这是可用键的列表:https://github.com/puppeteer/puppeteer/blob/main/src/common/USKeyboardLayout.ts