小编Kob*_* 27的帖子

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

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

起初,我只是等待输入字段加载,然后用page.type(). 用户名工作正常,但密码失败。我拆分page.type()page.click()然后page.keyboard.type()以隔离问题。

我正在用打字稿写作并用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)
Run Code Online (Sandbox Code Playgroud)
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"]')    // …
Run Code Online (Sandbox Code Playgroud)

node.js puppeteer

5
推荐指数
1
解决办法
6115
查看次数

标签 统计

node.js ×1

puppeteer ×1