Python Selenium Tutorial: How to Automate Form Filling & Data Entry

We all have that one boring, soul-crushing task: logging into a web portal and typing the same data over and over again. Whether it is inputting case files for the office or migrating employee data, manual data entry is a waste of human potential.

Why spend hours typing when a script can do it in seconds? Previously, we built a WhatsApp Bot using Selenium. Today, we apply the same logic to Automated Form Filling. We will write a script that opens a browser, finds the input fields, types the data, and submits it for you.

Tired of manual data entry? Learn how to use Python Selenium to automatically fill web forms, type text into inputs, and click submit buttons.

The Basic Script

Before running this, make sure you have the correct chromedriver installed that matches your Chrome version. Here is the complete code to locate an input box and type into it.

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

# Initialize the browser
driver = webdriver.Chrome()
driver.get("https://example.com/login")

# 1. Find the Username Box (Inspect Element to find ID)
# Always look for unique IDs first, they are the most reliable selectors
username_box = driver.find_element(By.ID, "user_login")

# 2. Type Data
username_box.clear() # Good practice: Clear field before typing to avoid duplicates
username_box.send_keys("admin_danang")

# 3. Click Submit
login_btn = driver.find_element(By.NAME, "submit_btn")
login_btn.click()

print("Form submitted successfully!")

Pro Tip: Inspect Element is Your Best Friend

The hardest part of Selenium is finding the right element. Right-click the input box on your target website and choose Inspect. Look for attributes like id="...", name="...", or unique classes. These are the keys Selenium needs to interact with the page.

Conclusion

Automation allows you to clone yourself. Once you master the send_keys and click commands, you can build scripts that handle thousands of data entries while you enjoy your coffee. Start small, and automate your workflow one form at a time.


Author: Marg | Daily Innovate Tech

Post a Comment for "Python Selenium Tutorial: How to Automate Form Filling & Data Entry"