Selenium is an open-source web-based automation tool. We'll learn how to interact with the Selenium form
We can use the find_element()
method to find text fields. We'll then use the send_keys()
method to fill the text fields, and use the click()
method to submit the form by clicking the submit button.
from selenium import webdriverimport time#specify where your chrome driver present in your pcPATH=r"C:\Users\educative\Documents\chromedriver\chromedriver.exe"#get instance of web driverdriver = webdriver.Chrome(PATH)#provide website url heredriver.get("http://demo.guru99.com/test/newtours/")#find input text fieldsuser_name = driver.find_element("name","userName")password = driver.find_element("name","password")#find submit buttonsubmit = driver.find_element("name","submit")#fill input text fieldsuser_name.send_keys("mercury")password.send_keys("mercury")#submit formsubmit.click()
webdriver
from selenium
package.time
.chromedriver.exe
in windows environment.webdriver
.driver.get()
method to open it.find_element()
method to get the input text fields—user_name
and password
.find_element()
method to get the submit button.send_keys()
method to fill the input text fields—user_name
and password
. We pass text to place in that field as a parameter to the send_keys()
method.click()
method to submit the form by clicking the submit button.Free Resources