请帮助我达到预期的效果。我将在页面上的每个输入字段中填充一个文本:'123‘。
let inputList = await page.$$('.form input');
inputList.map(async item => {
await item.type('123');
});预期结果-每个字段123个。
实际结果-最后一个输入字段为112233。
发布于 2018-03-08 03:20:47
在一般意义上,您正在尝试迭代数组并对数组中的每一项执行异步操作。您可以通过几种方式来实现这一点,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 functionhttps://stackoverflow.com/questions/48051709
复制相似问题