Forms let users send information on websites. Testing forms ensures data is sent correctly and the site works well.
When checking if a login form accepts correct username and password
When verifying a signup form saves new user details properly
When testing a contact form sends messages to the right place
When ensuring error messages show for missing or wrong inputs
When confirming that form buttons and fields respond as expected
Syntax
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By
# Open browser and go to page
browser = webdriver.Chrome()
browser.get('https://example.com/form')
# Find form fields and fill them
input_name = browser.find_element(By.ID, 'name')
input_name.send_keys('John Doe')
input_email = browser.find_element(By.ID, 'email')
input_email.send_keys('john@example.com')
# Submit the form
submit_button = browser.find_element(By.ID, 'submit')
submit_button.click()
Use clear locators like ID or name to find form elements.
Always close the browser after testing to free resources.
Examples
Fill a password field using the 'name' attribute locator.
driver.find_element(By.ID, 'input').send_keys('text') -> Option C
Quick Check:
send_keys() inputs text = A [OK]
Hint: Use send_keys() to type text in fields [OK]
Common Mistakes:
Using click() to enter text
Confusing submit() with typing
Forgetting to clear() before typing
3. What will be the output of this Selenium Python code snippet?
from selenium.webdriver.common.by import By
input_field = driver.find_element(By.NAME, 'email')
input_field.send_keys('user@example.com')
print(input_field.get_attribute('value'))
medium
A. user@example.com
B. email
C. None
D. SyntaxError
Solution
Step 1: Understand send_keys effect
The send_keys() method types the string into the input field.
Step 2: Check what get_attribute('value') returns
This returns the current text inside the input field, which is the typed email.
Final Answer:
user@example.com -> Option A
Quick Check:
Typed text = get_attribute('value') = B [OK]
Hint: get_attribute('value') shows typed input text [OK]
Common Mistakes:
Expecting get_attribute to return element name
Confusing attribute with placeholder
Assuming None if no submit
4. Identify the error in this Selenium Python code for submitting a form: