CodeSolved

Solved Programming Questions & Exercises

Automatic Submission of Sign Up Form

Practice Easy 1817/ Download 524 Views

Write a program that automatically fill and send the form below with random information

Help: You can use selenium


<! HTML DOCTYPE>
<html lang = "FA">
<Head>
<meta charst = "UTF-8">
<title> Registration Form </ taitle>
</hread>
<body>
<h2> Registration form </h2>
<Form id = "Signup-Form" action = "submit.html" method = "post">
<label for = "name"> Name: </Label>
<input type = "Text" id = "name" name = "name" Required> <br> <br>

<label for = "Email"> Email: </Label>
<input type = "email" id = "email" name = "Email" Required> <br> <br>

<label for = "password"> Password: </Label>
<input type = "password" id = "password" name = "password" Required> <br> <br>

<label for = "confirm-password"> Repeat Password: </Label>
<input type = "password" id = "confirm-password" name = "confirm-password" Required> <br> <br>

<Button Type = "Submit"> Registration </ Button>
</rem>
</body>
</tml>

1 Answers

You can use the following code to fill out and submit the form using Selenium:

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

# Browser Settings
driver = webdriver.Chrome()

# Open the form page
driver.get('file:///path/to/your/form.html')  # Enter your HTML file address

# Production of Random Information
name = f"User{random.randint(1, 100)}"
email = f"user{random.randint(1, 100)}@example.com"
password = "password123"

# Fill the form
driver.find_element(By.ID, 'name').send_keys(name)
driver.find_element(By.ID, 'email').send_keys(email)
driver.find_element(By.ID, 'password').send_keys(password)
driver.find_element(By.ID, 'confirm-password').send_keys(password)

# Send the form
driver.find_element(By.XPATH, '//button[text()="ثبت‌نام"]').click()

# Wait a little to see the result
time.sleep(5)

# Close the browser
driver.quit()

Note: Be sure to address the html file on the linedriver.get()Enter.

Ai Download Python

Submit answer

Submitting answers is currently unavailable.

×
×
Close