How To Locate Element By Tag Name Locator In Selenium

In the previous post we have seen “locators in Selenium“. In this post, we discuss “How To Locate Element By Tag Name Locator”. Find the below links on How to find elements on a web page using different types of locators.

1. “How To Locate Element By ID Locator
2. “How To Locate Element By Name Locator
3. “How To Locate Element By Class Name Locator
4. “How To Locate Element By Link Text/Partial Link Text Locator
5. “How To Locate Element By CSS Selector Locator
6. “How To Locate Element By XPath Locator

Coming to the actual post “How To Locate Element By Tag Name Locator”.

Tag Name Locator:

Tag Name locator is used to find the elements matching the specified Tag Name. It is very helpful when we want to extract the content within a Tag.

Syntax:

Script Explanation: 

Copy the below mentioned script and execute in your system. It executes as mentioned below:

  1. Opens Firefox Browser
  2. Navigates to Google.com
  3. Here we used, tagName(“a”) to get the links and used findElements method to store the list of all links on the google.com page
  4. Prints the size of total no. of links
  5. Print s the list of all the links available on the page

Value to be added in the By.tagName method:

Script:

How to locate element by tag name locator

Sumasri is a Sr. Software Test Engineer. Currently working in an MNC. She is a co-founder of Software Testing Material. She has an exclusive experience in the field of Software Testing. She writes here about Manual Testing and Automation Testing.

1 thought on “How To Locate Element By Tag Name Locator In Selenium”

  1. Very clear explanation

Leave a Comment

Share via
Copy link
Powered by Social Snap