Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Last active September 15, 2022 07:55
Show Gist options
  • Save SarahElson/2463f2bd45c5a180dc6e8b01ff7bd669 to your computer and use it in GitHub Desktop.
Save SarahElson/2463f2bd45c5a180dc6e8b01ff7bd669 to your computer and use it in GitHub Desktop.
How To Automate Filling In Web Forms With Python Using Selenium
import random
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
#lambdatest setup and opening the desired website
username = "Your LambdaTest Username"
accessToken = "Your LambdaTest Access Key"
gridUrl = "hub.lambdatest.com/wd/hub"
capabilities = {
'LT:Options' : {
"user" : "Your LambdaTest Username",
"accessKey" : "Your LambdaTest Access Key",
"build" : "your build name",
"name" : "your test name",
"platformName" : "Windows 11",
},
"browserName" : "Chrome",
"browserVersion" : "103.0",
}
url = "https://"+username+":"+accessToken+"@"+gridUrl
browser = webdriver.Remote(
command_executor=url,
desired_capabilities=capabilities
)
browser.maximize_window()
browser.get("https://ecommerce-playground.lambdatest.io/index.php?route=account/register")
#filling in the form
first_name = browser.find_element(By.ID, "input-firstname")
first_name.send_keys("FirstName")
last_name = browser.find_element(By.ID, "input-lastname")
last_name.send_keys("LastName")
random_email = str(random.randint(0,99999)) + "@example.com"
email = browser.find_element(By.ID, "input-email")
email.send_keys("[email protected]")
telephone = browser.find_element(By.ID, "input-telephone")
telephone.send_keys("+351999888777")
password = browser.find_element(By.ID, "input-password")
password.send_keys("123456")
password_confirm = browser.find_element(By.ID, "input-confirm")
password_confirm.send_keys("123456")
newsletter = browser.find_element(By.XPATH, value="//label[@for='input-newsletter-yes']")
newsletter.click()
terms = browser.find_element(By.XPATH, value="//label[@for='input-agree']")
terms.click()
continue_button = browser.find_element(By.XPATH, value="//input[@value='Continue']")
continue_button.click()
#asserting that the browser title is correct
assert browser.title == "Your Account Has Been Created!"
#closing the browser
browser.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment