Home > Automation Testing > Selenium WebDriver Locator: Tag Name

Selenium WebDriver Locator: Tag Name

This post was most recently updated on June 14th, 2019

Locator Type: Tag Name 

  • HTML document is structure of different html elements which normally contains start tag with attribute closing tag and some text within opening and closing tag. 
  • Opening tag consist within Tag Name within two angular brackets (‘<’ and ‘>’) while closing tag contains forward slash before Tag Name within angular brackets.

Java code to find web element using Tag Name. 

For single WebElement

WebElement element=driver.findElement(By.tagName(tag_Name)); 

For multiple WebElement

List<WebElement> elements=driver.findElements(By.tagName(tag_Name)); 

Steps to find web element availability or count for specific tag name.

  • Open url “https://www.societyhive.com/” in chrome browser.
  • Click F12 to open DevTools in chrome browser.
  • Click on elements tab and press shortcut key Ctrl+F.
  • Enter tag name to find count on web element with specific tag name.
Locate all anchor element by using “a”

Single element

WebElement inputElement=driver.findElement(By.tagName("input"));  

Multiple element

List<WebElement> allInputElements=driver.findElements(By.tagName("a"));

Sample code to print href attribute value for all anchor element:

Selenium Tutorial >>

This Article is TAGGED in , , , . BOOKMARK THE permalink.

Avatar photo
Neeraj Vishwakarma
Senior QA Engineer Skills: Automation Testing, Manual Testing, STLC, Java, Selenium Webdriver, Protractor, Database Testing.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">