TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Automation

Different Types of Locators in Selenium Webdriver

Overview

In this tutorial, we will learn different types of Locators in Selenium Webdriver. The locators are used to identify web page elements. The Selenium Webdriver class with the methods defined for locating elements on the web page.

Types of Locators

The locators are broadly classified into two types:

  • Attribute based Locators
  • Structure based Locators

Attribute based Locators

Attribute based locators reply on the attributes of the web elements. Examples of Attribute based locators are Id, Name, LinkText, ClassName and TagName.

Structure based Locators

Structure based locators reply on the structure of the page DOM(Document Object Model) to find the web elements. Examples of  this type of locators are XPath and CSS Selectors.

By abstract class

Selenium Webdriver provides an abstract class By with static methods that has implementations to locate elements within web pages.  Some of the static methods in this class are as follows:

  • By.id()
  • By.name()
  • By.tagName()
  • By.linkText()
  • By.partialLinkText()
  • By.className()
  • By.cssSelector()
  • By.xpath()

 

 

We can create custom locating mechanisms by extending the By class. We can override the finding methods to provide custom locating strategy.

Difference between findElement() and findElements() methods:

https://www.testingdocs.com/difference-between-findelements-and-findelement/

—

Selenium Tutorials on this website:

https://www.testingdocs.com/selenium-webdriver-tutorial/

Official Website:

https://www.selenium.dev/

Related Posts

Emma Tool

Automation /

Code Coverage Tools

Selenium 4 Automation Project

Automation /

Selenium 4 Project Setup on Ubuntu Linux

Testing webpage mobile-friendliness using a tool

Automation /

Testing webpage mobile-friendliness using a tool

Errors Code Testing Development

Automation /

Error Severity Metrics

Automation Environment Setup Verification

Automation /

Automation Environment Setup Verification

‹ Automation Reading Properties File› Program to Read Column from an Excel Sheet

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version