• Login
Wednesday, May 21, 2025
Blogue
  • Homepage
  • Web
    The WordPress Drama- Open Source at War

    The WordPress Drama: Open Source at War

    The Plan to Break Apart Google- RIP Chrome_

    The Plan to Break Apart Google: RIP Chrome?

    Andrew Tate’s Hustler’s University Hacked- What We Know

    Andrew Tate’s Hustler’s University Hacked: What We Know

    Scraping Websites with Various Scraper Frameworks (With Examples)

    Scraping Websites with Various Scraper Frameworks (With Examples)

    Git : Developer’s Favourite

    Git : Developer’s Favourite

    HTTP Status/Error Codes and How to Fix them

    HTTP Status/Error Codes and How to Fix them

    A Walkthrough to Hashing, Salting , and Verifying Passwords in NodeJS, Python, Golang, and Java

    A Walkthrough to Hashing, Salting , and Verifying Passwords in NodeJS, Python, Golang, and Java

    Guide to Googling

    Guide to Googling

    How To Submit a Form With Puppeteer and JavaScript

    How To Submit a Form With Puppeteer and JavaScript

  • Web Developer
    How to Detect Ad Blockers in a React.js Application

    How to Detect Ad Blockers in a React.js Application

    How to Create Responsive Image in CSS

    How to Create Responsive Image in CSS

    A Walkthrough to Hashing, Salting , and Verifying Passwords in NodeJS, Python, Golang, and Java

    A Walkthrough to Hashing, Salting , and Verifying Passwords in NodeJS, Python, Golang, and Java

    How To Take Screenshot With Puppeteer

    How To Take Screenshot With Puppeteer

    Web Scraping With JavaScript and Puppeteer

    Web Scraping With JavaScript and Puppeteer

    How to create a Responsive Website

    How to create a Responsive Website

    Top Frontend Frameworks To Learn

    Top Frontend Frameworks To Learn

    Full Stack Web Developer: A Guide to Learn

    Full Stack Web Developer: A Guide to Learn

  • Web Scraping
    Scraping Websites with Various Scraper Frameworks (With Examples)

    Scraping Websites with Various Scraper Frameworks (With Examples)

    Scraping Table Data into JSON File with Puppeteer

    Scraping Table Data into JSON File with Puppeteer

    How To Scrape Multiple Pages With Puppeteer and JavaScript

    How To Scrape Multiple Pages With Puppeteer and JavaScript

    How To Submit a Form With Puppeteer and JavaScript

    How To Submit a Form With Puppeteer and JavaScript

    How to Automate Form Submission with Puppeteer and Javascript

    How to Automate Form Submission with Puppeteer and Javascript

    How To Take Screenshot With Puppeteer

    How To Take Screenshot With Puppeteer

    Web Scraping With JavaScript and Puppeteer

    Web Scraping With JavaScript and Puppeteer

  • How To?
    How LinkedIn Powers Professional Networking: A Look Inside Its System Design

    How LinkedIn Powers Professional Networking: A Look Inside Its System Design

    Facebook: The Engine Behind the World’s Largest Social Network

    Facebook: The Engine Behind the World’s Largest Social Network

    Snapchat: The System Powering Snaps, Stories, and Lenses

    Snapchat: The System Powering Snaps, Stories, and Lenses

    How WhatsApp Powers Instant Communication for Billions

    How WhatsApp Powers Instant Communication for Billions?

    How Instagram Scales to Billions of Photos and Videos Daily

    How Instagram Scales to Billions of Photos and Videos Daily?

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    Effective Structure for Describe Image, Retell Lecture, and Summarize Spoken Text in PTE Academic

    Effective Structure for Describe Image, Retell Lecture, and Summarize Spoken Text in PTE Academic

    Understanding Marks Allocation in PTE Academic Tasks

    Understanding Marks Allocation in PTE Academic Tasks

    From Power-On to Productivity: How Your Operating System Comes to Life

    From Power-On to Productivity: How Your Operating System Comes to Life

  • Technology
    A Deep Dive into Physical Storage Devices: From Floppy Disks to Modern SSDs

    A Deep Dive into Physical Storage Devices: From Floppy Disks to Modern SSDs

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    The WordPress Drama- Open Source at War

    The WordPress Drama: Open Source at War

    25 Software Bugs That Changed the World

    25 Software Bugs That Changed the World

    The Plan to Break Apart Google- RIP Chrome_

    The Plan to Break Apart Google: RIP Chrome?

    Guide to Googling

    Guide to Googling

    How Video Streaming on the Internet Works

    How Video Streaming on the Internet Works

    Git : A short history

    Git : A short history

    A Walkthrough to Blockchain

    A Walkthrough to Blockchain

  • System Design
    How LinkedIn Powers Professional Networking: A Look Inside Its System Design

    How LinkedIn Powers Professional Networking: A Look Inside Its System Design

    Facebook: The Engine Behind the World’s Largest Social Network

    Facebook: The Engine Behind the World’s Largest Social Network

    Snapchat: The System Powering Snaps, Stories, and Lenses

    Snapchat: The System Powering Snaps, Stories, and Lenses

    How WhatsApp Powers Instant Communication for Billions

    How WhatsApp Powers Instant Communication for Billions?

    How Instagram Scales to Billions of Photos and Videos Daily

    How Instagram Scales to Billions of Photos and Videos Daily?

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    How YouTube Handles Billions of Videos Daily

    How YouTube Handles Billions of Videos Daily?

    How Spotify Streams Personalized Music to Millions in Real-Time?

    How Spotify Streams Personalized Music to Millions in Real-Time?

Submit Post
No Result
View All Result
  • Homepage
  • Web
    The WordPress Drama- Open Source at War

    The WordPress Drama: Open Source at War

    The Plan to Break Apart Google- RIP Chrome_

    The Plan to Break Apart Google: RIP Chrome?

    Andrew Tate’s Hustler’s University Hacked- What We Know

    Andrew Tate’s Hustler’s University Hacked: What We Know

    Scraping Websites with Various Scraper Frameworks (With Examples)

    Scraping Websites with Various Scraper Frameworks (With Examples)

    Git : Developer’s Favourite

    Git : Developer’s Favourite

    HTTP Status/Error Codes and How to Fix them

    HTTP Status/Error Codes and How to Fix them

    A Walkthrough to Hashing, Salting , and Verifying Passwords in NodeJS, Python, Golang, and Java

    A Walkthrough to Hashing, Salting , and Verifying Passwords in NodeJS, Python, Golang, and Java

    Guide to Googling

    Guide to Googling

    How To Submit a Form With Puppeteer and JavaScript

    How To Submit a Form With Puppeteer and JavaScript

  • Web Developer
    How to Detect Ad Blockers in a React.js Application

    How to Detect Ad Blockers in a React.js Application

    How to Create Responsive Image in CSS

    How to Create Responsive Image in CSS

    A Walkthrough to Hashing, Salting , and Verifying Passwords in NodeJS, Python, Golang, and Java

    A Walkthrough to Hashing, Salting , and Verifying Passwords in NodeJS, Python, Golang, and Java

    How To Take Screenshot With Puppeteer

    How To Take Screenshot With Puppeteer

    Web Scraping With JavaScript and Puppeteer

    Web Scraping With JavaScript and Puppeteer

    How to create a Responsive Website

    How to create a Responsive Website

    Top Frontend Frameworks To Learn

    Top Frontend Frameworks To Learn

    Full Stack Web Developer: A Guide to Learn

    Full Stack Web Developer: A Guide to Learn

  • Web Scraping
    Scraping Websites with Various Scraper Frameworks (With Examples)

    Scraping Websites with Various Scraper Frameworks (With Examples)

    Scraping Table Data into JSON File with Puppeteer

    Scraping Table Data into JSON File with Puppeteer

    How To Scrape Multiple Pages With Puppeteer and JavaScript

    How To Scrape Multiple Pages With Puppeteer and JavaScript

    How To Submit a Form With Puppeteer and JavaScript

    How To Submit a Form With Puppeteer and JavaScript

    How to Automate Form Submission with Puppeteer and Javascript

    How to Automate Form Submission with Puppeteer and Javascript

    How To Take Screenshot With Puppeteer

    How To Take Screenshot With Puppeteer

    Web Scraping With JavaScript and Puppeteer

    Web Scraping With JavaScript and Puppeteer

  • How To?
    How LinkedIn Powers Professional Networking: A Look Inside Its System Design

    How LinkedIn Powers Professional Networking: A Look Inside Its System Design

    Facebook: The Engine Behind the World’s Largest Social Network

    Facebook: The Engine Behind the World’s Largest Social Network

    Snapchat: The System Powering Snaps, Stories, and Lenses

    Snapchat: The System Powering Snaps, Stories, and Lenses

    How WhatsApp Powers Instant Communication for Billions

    How WhatsApp Powers Instant Communication for Billions?

    How Instagram Scales to Billions of Photos and Videos Daily

    How Instagram Scales to Billions of Photos and Videos Daily?

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    Effective Structure for Describe Image, Retell Lecture, and Summarize Spoken Text in PTE Academic

    Effective Structure for Describe Image, Retell Lecture, and Summarize Spoken Text in PTE Academic

    Understanding Marks Allocation in PTE Academic Tasks

    Understanding Marks Allocation in PTE Academic Tasks

    From Power-On to Productivity: How Your Operating System Comes to Life

    From Power-On to Productivity: How Your Operating System Comes to Life

  • Technology
    A Deep Dive into Physical Storage Devices: From Floppy Disks to Modern SSDs

    A Deep Dive into Physical Storage Devices: From Floppy Disks to Modern SSDs

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    The WordPress Drama- Open Source at War

    The WordPress Drama: Open Source at War

    25 Software Bugs That Changed the World

    25 Software Bugs That Changed the World

    The Plan to Break Apart Google- RIP Chrome_

    The Plan to Break Apart Google: RIP Chrome?

    Guide to Googling

    Guide to Googling

    How Video Streaming on the Internet Works

    How Video Streaming on the Internet Works

    Git : A short history

    Git : A short history

    A Walkthrough to Blockchain

    A Walkthrough to Blockchain

  • System Design
    How LinkedIn Powers Professional Networking: A Look Inside Its System Design

    How LinkedIn Powers Professional Networking: A Look Inside Its System Design

    Facebook: The Engine Behind the World’s Largest Social Network

    Facebook: The Engine Behind the World’s Largest Social Network

    Snapchat: The System Powering Snaps, Stories, and Lenses

    Snapchat: The System Powering Snaps, Stories, and Lenses

    How WhatsApp Powers Instant Communication for Billions

    How WhatsApp Powers Instant Communication for Billions?

    How Instagram Scales to Billions of Photos and Videos Daily

    How Instagram Scales to Billions of Photos and Videos Daily?

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    How Netflix Delivers High-Quality Streaming to Millions Worldwide

    How YouTube Handles Billions of Videos Daily

    How YouTube Handles Billions of Videos Daily?

    How Spotify Streams Personalized Music to Millions in Real-Time?

    How Spotify Streams Personalized Music to Millions in Real-Time?

Submit Post
No Result
View All Result
Blogue
  • Homepage
  • Web
  • Web Developer
  • Web Scraping
  • How To?
  • Technology
  • System Design

How to Automate Form Submission with Puppeteer and Javascript

The Blogue Team by The Blogue Team
July 10, 2023
in How To?, JavaScript, Programming, Puppeteer, Tutorial, Web, Web Scraping
Reading Time: 5 mins read
334
A A
0
338
SHARES
1.1k
VIEWS
Share on FacebookShare on XShare on RedditShare on Whatsapp

In this tutorial, we’ll look at utilising Puppeteer to automate form submission. An open source Node library called Puppeteer offers a high-level API for managing browsers based on Chrome or Chromium via the DevTools Protocol. With Puppeteer, you can automate any task that you can carry out using a Chrome browser. A puppeteer is thus a perfect tool for test automation and site scraping. Everything you need to know about using Puppeteer to automate form submission will be covered in this post. We will talk about it.

  • Automated form submission
  • Using Puppeteer selectors to target form inputs
  • Submitting a form with attachments
we can simply add it to our node project with npm install or yarn add command. Let’s start by creating a new folder.    # create a new folder and navigate inside it
    mkdir form_demo
    cd form_demo

Inside our new project folder we can initialize a new Node project by running the following command.

Automating form submission

We verified Puppeteer is installed and working as expected. Now we can move forward with our first form submission. The first example is going to be super simple. We will navigate to yelp.com website and search for pizza delivery near Toronto, Canada.

First let’s visit the yelp.com.

s A71B946C27C415C359D6F3F8D869340BE0C4ED0E129D593DA5D053640B7463E5 1620322697831 image
s A71B946C27C415C359D6F3F8D869340BE0C4ED0E129D593DA5D053640B7463E5 1620322884464 image

If we open our Dev Tools in Chrome and start inspecting the webpage we can see that the find input has an id called find_desc. We can also see that the near input has an ID of dropperText_Mast and the search button has an id of header-search-submit. We can use this information to write our automation script.

    const puppeteer = require('puppeteer');
    async function main() {
        const browser = await puppeteer.launch({
            headless: false
        });
        const page = await browser.newPage();
        await page.goto('https://www.yelp.com/');
        await page.type('#find_desc', 'Pizza Delivery');
        await page.type('#dropperText_Mast', 'Toronto, ON');
        await page.click('#header-search-submit');
        await page.waitForTimeout(5000); // wait for 5 secondsawait browser.close();
    }
    main();

In the script above we are opening up a new browser instance. We are grabbing the inputs by id on lines 8 and 9. In Puppeteer we are able to target DOM elements by their id. We are using the type function from Puppeteer to populate the inputs. The first parameter of the type function is the targeted DOM element and the second argument is the string that we want Puppeteer to type for us. Note that we can also pass class name as a first argument. For instance if find_desc was a class instead of an Id name, we could have done this

    await page.type('.find_desc', 'Pizza Delivery');

On line 10 we are using the click function to emulate button click. The click function accepts a string identifier that corresponds to a DOM node.

Let’s run this script and see it in action here:

Let’s take a look at another example where we are going to target the input by name. For this next example, I am going to be using Github’s login page.

s A71B946C27C415C359D6F3F8D869340BE0C4ED0E129D593DA5D053640B7463E5 1620325667804 image

If we open Google Dev Tools and inspect the form here we will see that this form inputs have name property as well as id. Take a look at the code snippet below.

    async function withInputName() {
        const browser = await puppeteer.launch({
            headless: false
        });
        const page = await browser.newPage();
        await page.goto('https://github.com/login');
        
        await page.type('input[id=login_field]', 'John');
        await page.type('input[name=password]', 'Password');
        await page.evaluate(() => {
            document.querySelector('input[type=submit]').click();
        });
    }
    withInputName();

As you can see we are using a different type of syntax here. On line 8 we are targeting input by id then on line 9 targeting the input element by name property. We can also target input by type as you can see on line 11. Feel free to the syntax you feel comfortable with, there’s no functional difference between them.

Submitting a form with attachments

Next, we are going to take a look at how we can upload a file Puppeteer. We are going to use this demo form from W3 school to demonstrate this. Let’s dive into the code.

    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.$("input[type=file]");
        await element.uploadFile('./myfile.pdf');
    }
    uploadFile();

Notice that we are selecting the input element with page.$ function provided by Puppeteer. This returns the native DOM element. This element is able to access all the native browser APIs. In the next line we are using the uploadFile function to attach a file from local file system.

When you run the script you will see that the file from local path is getting attached to the form as shown below.

s A71B946C27C415C359D6F3F8D869340BE0C4ED0E129D593DA5D053640B7463E5 1620331388677 image

Happy Coding …

Tags: Chromiumformform submissionscraping
Share135Tweet85ShareSend
Previous Post

How To Take Screenshot With Puppeteer

Next Post

Linked List with JavaScript

The Blogue Team

The Blogue Team

We are a team of passionate bloggers

Related Posts

How LinkedIn Powers Professional Networking: A Look Inside Its System Design
How To?

How LinkedIn Powers Professional Networking: A Look Inside Its System Design

by The Blogue Team
December 18, 2024
1.1k
A Deep Dive into Physical Storage Devices: From Floppy Disks to Modern SSDs
Storage

A Deep Dive into Physical Storage Devices: From Floppy Disks to Modern SSDs

by The Blogue Team
December 17, 2024
1.1k
Facebook: The Engine Behind the World’s Largest Social Network
Facebook

Facebook: The Engine Behind the World’s Largest Social Network

by The Blogue Team
December 17, 2024
1.1k
Load More
Next Post
Linked List with JavaScript

Linked List with JavaScript

Where Writing Happens

  • Homepage
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2025 Blogue - Designed By Najus Digital.

Welcome Back!

Sign In with Google
OR

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Refresh
No Result
View All Result
  • Login

© 2025 Blogue - Designed By Najus Digital.

*By registering into our website, you agree to the Terms & Conditions. and Privacy Policy.
Enable Notifications OK No thanks