'How to fill all fields using puppeteer?
I use page.type to fill a field using puppeteer. If you have a multiple selector, then it will fill the first found field.
My goal is to fill all inputs that match the selector. Ex : fill all textinput with class "red"
await page.type('input.red', 'your text here');
this will just fill the first input with red class and not fill other inputs with red class.
Solution 1:[1]
You can try:
const elHandleArray = await page.$$('input[class="red"]') // Custom selector
for await (const item of elHandleArray) {
await item.type('your text')
}
This will search all the elements that matches the params and type the text. You probably gonna need to filter the type of input, to difference text fields and radios/box.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Carlos Giongo |
