Tag Name Locator


Tag Name Locator is used to find the elements matching the specified Tag Name. It is very useful when you are finding similar tags on webpage.

Scenario:
Find No of Links and Print the name of the Links on Web Page

Following is the steps to locate the element using Tag Name on webpage.

    Right click on SIGN-ON webelement on the page and select inspect option in the context menu




  
Syntax for locating a web element using its Tag Name is written as:

driver.find_element(By.TAG_NAME,<tagName>)
or
driver.find_element_by_tag_name(<tagName>)

Script:
from selenium import webdriver
from selenium.webdriver.common.by import By
chromePath=
"C:\\BrowserDriver\\chromedriver.exe"


driver=webdriver.Chrome(executable_path=chromePath)
driver.get(
"http://newtours.demoaut.com")

List=[]
List= driver.find_elements_by_tag_name(
"a")
 print(“No of Links On WebPage is “,len(List))

for Eleobj in List:
    print(“Link Test is “,Eleobj.text)

Out put : It will print all link names

Comments