How to fill an input field using Puppeteer?

0 votes

I'm using Puppeteer for E2E test, and I am now trying to fill an input field with the code below:

await page.type('#email', 'test@example.com');

It worked, but I found the email address was typed into the field one character by one character as if a real human being was typing.

Is it possible to fill the input field with the email address all at one time?

Oct 16 in Node-js by kartik
• 35,720 points
252 views

1 answer to this question.

0 votes

Hello @kartik,

Just set value of input like this:

await page.$eval('#email', el => el.value = 'test@example.com');

Here is an example of using it on Wikipedia:

const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://en.wikipedia.org', {waitUntil: 'networkidle2'});

    await page.waitFor('input[name=search]');

    // await page.type('input[name=search]', 'Adenosine triphosphate');
    await page.$eval('input[name=search]', el => el.value = 'Adenosine triphosphate');

    await page.click('input[type="submit"]');
    await page.waitForSelector('#mw-content-text');
    const text = await page.evaluate(() => {
        const anchor = document.querySelector('#mw-content-text');
        return anchor.textContent;
    });
    console.log(text);
    await browser.close();
})();

Hope it helps!!

Thank You!!

answered Oct 16 by Niroj
• 77,920 points

Related Questions In Node-js

0 votes
1 answer

How do you reinstall an app's dependencies using npm?

Hello @kartik, The easiest way is  to delete node_modules folder ...READ MORE

answered Jul 12 in Node-js by Niroj
• 77,920 points
255 views
0 votes
1 answer

How to write a test which expects an Error to be thrown in Jasmine?

Hello @kartik, Try using an anonymous function instead: expect( ...READ MORE

answered Jul 13 in Node-js by Niroj
• 77,920 points
79 views
0 votes
1 answer

How TO install a local module using npm?

Hello @kartik, In the local module directory: $ cd ...READ MORE

answered Jul 13 in Node-js by Niroj
• 77,920 points
68 views
0 votes
1 answer

How to create an HTTPS server in Node.js?

Hello @kartik, The minimal setup for an HTTPS ...READ MORE

answered Jul 13 in Node-js by Niroj
• 77,920 points
85 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 77,920 points
3,498 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 77,920 points
418 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 77,920 points
287 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 77,920 points
4,197 views
0 votes
1 answer

How to create a directory if it doesn't exist using Node.js?

Hello @kartik, Try: var fs = require('fs'); var dir = ...READ MORE

answered Jul 9 in Node-js by Niroj
• 77,920 points
540 views
0 votes
1 answer

How to Install a local module using npm?

Hello @kartik, This is what worked for me: npm ...READ MORE

answered Jul 9 in Node-js by Niroj
• 77,920 points
103 views