60 MINS

Build With Me: Auto Form Filler

Build With Me 01

The Auto Form Filler

Welcome to our first Build With Me session. We aren't just looking at snippets today — we are building a complete, working Playwright bot from scratch. Our goal: Build a bot that reads a CSV of user data and automatically fills out and submits a target registration form for every user.

Step 1: The Setup

First, we need to initialize our headless browser. In the editor, start by importing Playwright and setting up the context.

Text
from playwright.sync_api import sync_playwright
import csv
import time

def run_form_bot():
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False) # Keep visible so we can watch it
        page = browser.new_page()
        
        # Go to the target
        page.goto(https://example.com/register)
        print(Target acquired.)

Step 2: Parsing the Data

Next, we need data to inject. We'll use Python's built-in CSV reader to pull from our local dataset.

Text
# Read our mock database
        with open(users.csv, r) as file:
            reader = csv.DictReader(file)
            for row in reader:
                print(f"Processing user: {row[name]}")
                
                # Now we target the DOM
                page.fill(input[name=full_name], row[name])
                page.fill(input[name=email], row[email])
                
                # Handle dropdowns
                page.select_option(select#role, row[role])
                
                # Submit
                page.click(button[type=submit])
                
                # Wait for success message before next loop
                page.wait_for_selector(.success-banner)
                print(f"Successfully registered {row[name]}")
                
                # Go back for the next user
                page.goto(https://example.com/register)

Your Turn: Look at the Live Target on the left. Find the CSS selectors for the inputs and update the script in your editor to match them. Click Run to watch your bot take over the browser!

Lab Overview

Objectives & Tasks

Review the tasks below and follow the interactive instructions to complete this module.

Clearance Required

Interactive sandbox environments consume dedicated compute resources and are restricted to authenticated operators.

Sign In

Knowledge Check

Ready to test your understanding of Build With Me: Auto Form Filler?

Back