Handling Web Forms and Buttons
Filling inputs
selenium_form_fill.py
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
try:
driver.get("https://httpbin.org/forms/post")
driver.find_element(By.NAME, "custname").send_keys("Alice")
driver.find_element(By.NAME, "custtel").send_keys("123")
driver.find_element(By.NAME, "custemail").send_keys("a@example.com")
# submit
driver.find_element(By.CSS_SELECTOR, "form").submit()
print(driver.title)
finally:
driver.quit()selenium_form_fill.py
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
try:
driver.get("https://httpbin.org/forms/post")
driver.find_element(By.NAME, "custname").send_keys("Alice")
driver.find_element(By.NAME, "custtel").send_keys("123")
driver.find_element(By.NAME, "custemail").send_keys("a@example.com")
# submit
driver.find_element(By.CSS_SELECTOR, "form").submit()
print(driver.title)
finally:
driver.quit()Tips
- If
.submit().submit()doesnβt work, click a submit button element instead - Always prefer stable selectors (IDs, name)
If this helped you, consider buying me a coffee β
Buy me a coffeeWas this page helpful?
Let us know how we did
