Categories
JavaScript Answers

How to fill an input field using Puppeteer and JavaScript?

Spread the love

To fill an input field using Puppeteer and JavaScript, we call the page.evaluate method.

For instance, we write

await page.evaluate(() => {
  const email = document.querySelector("#email");
  email.value = "test@example.com";
});

to call page.evaluate with a callback that gets the input with querySelector.

And we set its value to the input value.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *