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 webdriver import time #specify where your chrome driver present in your pc PATH=r"C:\Users\educative\Documents\chromedriver\chromedriver.exe" #get instance of web driver driver = webdriver.Chrome(PATH) #provide website url here driver.get("http://demo.guru99.com/test/newtours/") #find input text fields user_name = driver.find_element("name","userName") password = driver.find_element("name","password") #find submit button submit = driver.find_element("name","submit") #fill input text fields user_name.send_keys("mercury") password.send_keys("mercury") #submit form submit.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.RELATED TAGS
CONTRIBUTOR
View all Courses