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
1 Answer
Reset to default 23You 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
版权声明:本文标题:javascript - Is it possible to simulate pressing 'Down' arrow? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738654247a2105051.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论