Wednesday, March 26, 2025

#1 Basic form filling using selenium

Automate Google Form Filling Using Python and Selenium

Filling out forms manually is a tedious task, but with Python and Selenium, we can automate it in just a few steps! 🚀

Step 1: Create a Google Form

  1. Head over to Google Forms and create a form similar to this:

    • Name (Short Answer)

    • Mobile Number (Short Answer)

    • Email (Short Answer)


  1. Publish your form and copy the form URL (e.g., https://forms.gle/ZVKdhTJYqeHT4W1o6).

  2. Open the form in Google Chrome.

  3. Right-click on each input field, select Inspect, then right-click on the <input> tag and select Copy XPath.

  4. Save the XPath values for later use.


Step 2: Automate Form Filling with Python

Install Dependencies

First, install Selenium:

pip install selenium

Also, ensure you have the Chrome WebDriver installed and placed in your system's PATH.

Create form_fill.py

Open Visual Studio Code and create a file named form_fill.py.

from selenium import webdriver
import time

# Initialize WebDriver
web = webdriver.Chrome()
web.get('https://forms.gle/ZVKdhTJYqeHT4W1o6')
web.maximize_window()

time.sleep(2)  # Allow the page to load

# Fill out the form
sname = "RM.Chandrasekaran"
name = web.find_element('xpath', '//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input')
name.send_keys(sname)

time.sleep(2)

mobile = "999999999"
mobil = web.find_element('xpath', '//*[@id="mG61Hd"]/div[2]/div/div[2]/div[2]/div/div/div[2]/div/div[1]/div/div[1]/input')
mobil.send_keys(mobile)

time.sleep(2)

email = 'abc@a.com'
emai = web.find_element('xpath', '//*[@id="mG61Hd"]/div[2]/div/div[2]/div[3]/div/div/div[2]/div/div[1]/div/div[1]/input')
emai.send_keys(email)

time.sleep(2)

# Click Submit Button
submit = web.find_element('xpath', '//*[@id="mG61Hd"]/div[2]/div/div[3]/div[1]/div[1]/div/span/span')
submit.click()

time.sleep(5)  # Wait before closing the browser

print("Form Submitted Successfully! 🎉")

# Close the browser
web.quit()

Step 3: Run the Script

Simply run the script using:

python form_fill.py

And just like that, your form gets submitted automatically! 😎


Conclusion

Automating repetitive tasks like form filling can save time and effort. This method can be expanded for bulk form submissions or integrated with databases to auto-fill dynamic values.

Happy Coding! 💻✨ 

No comments:

Post a Comment

#2 DevOps Beginner's - Hands-on

  DevOps Oru Saravedi! 💥🚀 aurmc2024@gmail.com Step 1: Git Anna Kitta Po! 🎩 👉 Mudhalil Git install pannunga, illa na code track panna...