I have some code that is filling out a form. It is able to find all the parts I need but it failes to type in one of them.
At first, I started by just waiting for the input fields to load, then wrote to them with page.type()
. The username worked fine but the password failed.
I split page.type()
to page.click()
and then page.keyboard.type()
in order to isolate the problem.
I'm writing with typescript and running the files with ts-node
The same error was raised on both runs:
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"]');
This code definitely worked in another project I had, what can be causing this error?
The error occurred because user.password
was not a string. It was undefined
.
In my case, I was passing a Number
instead of a String
. Number is not iterable indeed, should pass a String
.
You can convert number to string using JSON.stringify
await page.keyboard.type(JSON.stringify(user.password));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With