How to fill an input field using Puppeteer and JavaScript?

Estimated read time 1 min read

To fill an input field using Puppeteer and JavaScript, you can use the page.type() method from the Puppeteer API. The page.type() method simulates typing into an input field.

Here’s an example:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('');

  // Select the input field
  const inputField = await page.$('#input-field');

  // Fill the input field with text
  await inputField.type('Hello, world!');

  await browser.close();

In this example, Puppeteer is used to launch a browser, create a new page, and navigate to a website. The input field is selected using the page.$() method and the input field is filled with text using the inputField.type() method. Finally, the browser is closed using the browser.close() method.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply