Send keys without specifying element in Python Selenium webdriver


We can send keys without specifying elements in Python with Selenium webdriver. The tagname input is used for all the edit boxes. We shall use the find_element_by_tag_name method and pass input as a parameter to that method.

Thus we need not mention element attributes explicitly. Let us investigate the html code of an element which can be identified with tagname input.

Example

from selenium import webdriver
#set geckodriver.exe path
driver = webdriver.Firefox(executable_path="C:\geckodriver.exe")
driver.implicitly_wait(0.5)
driver.get("https://www.tutorialspoint.com/index.htm")
#identify element with tagname
l = driver.find_element_by_tag_name("input")
l.send_keys("Selenium")
#obtain value obtained
print("Value entered: ")
print(l.get_attribute('value'))
driver.quit()

Output

Updated on: 02-Feb-2021

948 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements