我想用 puppeteer 自动填写表单。 我填写第一个输入,然后单击一个按钮,然后创建一个具有焦点的新输入字段。
我如何选择这个输入?我可以使用 document.activeElement 以及如何使用吗?
let newActivity = 'button.new_activity'
await page.waitForSelector(newActivity)
await page.click(newActivity)
// find active/focused input
await page.type(focusedInput, 'message')
最佳答案
您可以使用evaluateHandle
获取元素句柄,然后对该元素调用type
函数。
const el = await page.evaluateHandle(() => document.activeElement);
await el.type('message');
关于javascript - 如何在 Puppeteer 中查找 document.activeElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57522891/