How to type a text in input box in puppeteer

Vinirdishtith Rana picture Vinirdishtith Rana · Feb 14, 2018 · Viewed 13.9k times · Source

I need to know how can we type a string in input box using puppeteer. I know it can be done like this:

await page.type('input[name=pickup]', 'test comment', {delay: 200})

But what if the input box does not have a name or id, and instead it has a value name or title id? Like this:

await page.type('[title id^="pickupAgingComment"]', 'test comment', {delay: 200})

OR

await page.type('[value name^="pickupAgingComment"]', 'test comment', {delay: 200}) 

The last two does not work actually.

Answer

Vinirdishtith Rana picture Vinirdishtith Rana · Feb 14, 2018

ok, I just figured out with this:

await page.type('input[name=pickupAgingComment]', 'test comment', {delay: 20})

Though the selector is a value name, I tried removing value and used just name literal. It is working for value name also.