Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to type a text in input box in puppeteer

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.

like image 790
Vinirdishtith Rana Avatar asked Feb 14 '18 17:02

Vinirdishtith Rana


People also ask

How do you fill a puppeteer?

Submitting a form with attachments async function uploadFile() { const browser = await puppeteer. launch({ headless: false }); const page = await browser. newPage(); await page. goto('https://www.w3schools.com/howto/howto_html_file_upload_button.asp'); const element = await page.

How do you find the input value of a puppeteer?

Just set value of input like this: await page. $eval('#email', el => el. value = '[email protected]');

How do you find the element by name in puppeteer?

puppeteer find element by text You have to form XPath based on the text so that you can find the element. Once you form the XPath then you can use the $x method to find the element.


1 Answers

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.

like image 124
Vinirdishtith Rana Avatar answered Sep 27 '22 20:09

Vinirdishtith Rana