Identifying the WebElement by “Tag Name ” locator.It takes String as an argument. If element doesn’t identified it throws an exception as NoSuchElementException.
Syntax: driver.find_element(By.TAG_NAME,"HTML_Tag_Name") Tag names such as <input> , <p> , <pre> , <a> , <div> etc can be used.
Example: In the below example we will launch the webpage and enter the text in the edit box using Tag Name locator value.
TagName_Locator.py
from selenium import webdriver import time from selenium.webdriver.common.by import By driver = webdriver.Chrome("/Users/admin/Documents/Skill2Lead/Others/drivers/chromedriver.exe") driver.get("http://www.dummypoint.com/seleniumtemplate.html") time.sleep(2) ele = driver.find_element(By.TAG_NAME,"input") ele.send_keys("Skill2Lead_TagName") # OR driver.find_element(By.TAG_NAME,"input").send_keys("Skill2Lead_TagName") time.sleep(5) driver.quit()