【发布时间】:2021-07-02 04:15:40
【问题描述】:
我有一些代码正在填写表格。它能够找到我需要的所有部分,但无法输入其中之一。
一开始,我只是等待输入字段加载,然后写信给他们page.type()。用户名工作正常,但密码失败。
我将page.type() 拆分为page.click() 然后page.keyboard.type() 以隔离问题。
我正在使用 typescript 编写并使用 ts-node 运行文件
两次运行都出现了同样的错误:
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)
await page.waitFor('input[type="text"]') // Makes sure the form was loaded
await page.type('input[type="text"]', user.username);
await page.waitFor('input[type="password"]') // Makes sure the form was loaded
try{
// await page.type('input[type="password"]', user.password);
await page.click('input[type="password"]'); // Click password field
await page.waitFor(5000)
await page.keyboard.type(user.password);
}
catch(e){
console.error(e)
}
await page.waitFor('input[type="submit"]') // Makes sure the form was loaded
await page.click('input[type="submit"]');
这段代码在我的另一个项目中确实有效,是什么导致了这个错误?
【问题讨论】:
-
是user.password里面的字符串吗?
-
@Md.AbuTaher 是的
-
也许你没有传递字符串,而是 int 或 object。你能仔细检查一下吗?
-
@Md.AbuTaher 就是这样,我忘记定义密码值了。