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

    Automation /

    Dart return Statement

    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 Reading Properties File› Program to Read Column from an Excel Sheet

    Recent Posts

    • Running Tests in Parallel with Selenium Grid
    • Advanced Selenium Features
    • Locating Web Elements
    • Running the Test Script
    • Writing Your First Selenium Test Script
    • Getting Started with Selenium Automation Testing
    • Setting Up the Environment
    • How can you monitor the Quality Assurance Audit?
    • Leveraging LambdaTest with Appium 2.0
    • Appium 2.0 Plugins ListAppium 2.0 Plugins
    • Touch Actions and Multi-Touch Actions
    • Changes in Drivers and Classes
    • Appium Inspector
    • Capabilities in Appium 2.0
    • Appium 2.0 Driver ListAppium 2.0 Driver Installation & Management
    CyberLink Multimedia Software

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com