根据https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepresskey-options,您可以使用Puppeteer模拟按键操作。
以下是我的操作:
如何模拟“回车键”来提交表单?
以下是我的操作:
// First, click the search button
await page.click('#outer-container > nav > span.right > span.search-notification-wrapper > span > form > input[type="text"]');
// Focus on the input field
await page.focus('#outer-container > nav > span.right > span.search-notification-wrapper > span > form > input[type="text"]');
// Enter some text into the input field
await page.type("Bla Bla");
// Press Enter to search -> this doesn't work!
await page.press("Enter");
按下后没有任何反应,基本上被忽略了。如何模拟“回车键”来提交表单?
const form = await page.$('#outer-container > nav > span.right > span.search-notification-wrapper > span > form'); await form.evaluate(form => form.submit());
- codtex