Handling Web Forms and Buttons
Filling inputs
Section titled “Filling inputs”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()- If
.submit()doesn’t work, click a submit button element instead - Always prefer stable selectors (IDs, name)
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading