Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  39] [ 7]  / answers: 1 / hits: 154086  / 7 Years ago, mon, december 25, 2017, 12:00:00

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', '[email protected]');


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?


More From » node.js

 Answers
19

Just set value of input like this:


await page.$eval('#email', el => el.value = '[email protected]');

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.waitForSelector('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();
})();

[#55599] Wednesday, December 20, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elvisissacg

Total Points: 410
Total Questions: 108
Total Answers: 121

Location: Monaco
Member since Tue, Jun 16, 2020
4 Years ago
;