如何修复Node.js puppeter keyboard.type()导致的TypeError

如何修复Node.js puppeter keyboard.type()导致的TypeError,node.js,puppeteer,Node.js,Puppeteer,我有一些代码正在填写表格。它能够找到我需要的所有零件,但它无法键入其中一个零件 起初,我只是等待输入字段加载,然后使用page.type()对其进行写入。用户名工作正常,但密码失败。 我将page.type()拆分为page。单击() 我用typescript写,用 在两次运行中都出现了相同的错误: TypeError: text is not iterable at Keyboard.type (...\node_modules\puppeteer\lib\Input.js:162:2

我有一些代码正在填写表格。它能够找到我需要的所有零件,但它无法键入其中一个零件

起初,我只是等待输入字段加载,然后使用
page.type()
对其进行写入。用户名工作正常,但密码失败。 我将
page.type()
拆分为
page。单击()

我用typescript写,用

在两次运行中都出现了相同的错误:

TypeError: text is not iterable
    at Keyboard.type (...\node_modules\puppeteer\lib\Input.js:162:24)
    at Keyboard.<anonymous> (...\node_modules\puppeteer\lib\helper.js:112:23)
    at ...\src\backend\index.ts:67:37
    at step (...\src\backend\index.ts:33:23)
    at Object.next (...\src\backend\index.ts:14:53)        
    at fulfilled (...\src\backend\index.ts:5:58)

这段代码在我的另一个项目中确实有效,是什么导致了这一错误?

发生错误是因为
user.password
不是字符串。它是
未定义的
在我的例子中,我传递的是
数字
,而不是
字符串
。数字实际上是不可编辑的,如果传递一个
字符串

您可以使用JSON将数字转换为字符串。stringify

await page.keyboard.type(JSON.stringify(user.password));

是user.password中的字符串吗?@Md.AbuTaher yesma可能不是传递字符串,而是int或object。你能再检查一遍吗?@Md.AbuTaher就是这样,我忘记定义密码值了。谢谢。我一直在搜索这个问题,发现
未定义的
是根本原因
await page.keyboard.type(JSON.stringify(user.password));