gpt4 book ai didi

javascript - Puppeteer.Iteration elementHandle 数组问题

转载 作者:行者123 更新时间:2023-12-03 02:47:06 25 4
gpt4 key购买 nike

请帮助我达到预期的结果。我将用文本填充页面上的每个输入字段:“123”。

let inputList = await page.$$('.form input');
inputList.map(async item => {
await item.type('123');
});

预期结果 - 每个字段 123。

最后一个输入字段的实际结果 - 112233。

page.$$(selector) API

最佳答案

一般来说,您正在尝试迭代数组并对数组中的每个项目执行异步操作。您可以通过多种方式实现这一点,for ... of 循环是一种方式。如果您不想循环而是想迭代,可以这样做:

await inputList.reduce(async (previousVal, currentVal) => {
await previousVal; // wait for the promise returned by the previous asynchronous call
return currentVal.type('123'); // call the next elementHandle in the array
}, Promise.resolve()); // the initial value that is passed to the callback function

关于javascript - Puppeteer.Iteration elementHandle 数组问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48051709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com