Assignment Solution
user_9132356
python
a year ago
1.2 kB
2
Indexable
Never
from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC # Set up WebDriver for Chrome driver = webdriver.Chrome() # Navigate to the web form's URL url = "https://www.stealmylogin.com/demo.html" driver.get(url) # Sample Details Used for Login username = "shivanshushukla" password = "password" # Locate form elements and fill them in with data name_field = driver.find_element(By.NAME, "username") name_field.send_keys(username) email_field = driver.find_element(By.NAME, "password") email_field.send_keys(password) # Click the submit button submit_button = driver.find_element(By.XPATH, "/html/body/form/input[3]") submit_button.click() # Wait for confirmation page to load or verify success message try: confirmation_element = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, "h1")) ) print("Form submitted successfully!") except: print("Form submission unsuccessful.") # Close the web browser driver.quit()