Locators Basics for Selenium (Selenium 4 – Session 2)


Introduction to Locators

  • Locators help Selenium in finding the UI elements on Web pages.
  • We can use these locators in our test automation code to locate the UI elements on the Web pages.

Different types of Locators

The below are the different types of locators which can be used for locating the UI elements on the Web Pages:

HTML Basics for Locators

Having knowledge of below HTML basics will help you in understanding the locators better:
  1. Take any simple web page say and inspect it to find its html code
  2. Let’s decode the above to create our own web page similar to above
    1. Basic structure of HTML
    2. Title
    3. Paragraphs
    4. Attributes
  3. Inspecting few UI Elements on the web pages from and applications

Demonstrating Different types of Locators using Selenium

  • id  – Entering text into the text area field on omayo
  • name – Enter text into the text box field on omayo
  • class name – Click on the drop-down button on omayo
  • link text– Click on the link say compendium dev on omayo
  • xpath expression – Click on ‘Login’ button on omayo
  • css selector– Click on ‘Login’ button on omayo

Locators Priority

Though there are different types of locators available for locating the UI elements on the Web Pages, we need to use any one of them based on their priority.
The below is the priority order in which we need to select and use the locators :

SelectorsHub for Auto-generating the XPath Expressions and CSS Selectors

  1. We should not depend on Tools for generating XPath Expressions and CSS Selectors, instead we should learn by ourselves
  2. Manual Creation of XPath Expressions and CSS Selectors, will be explained later when required during the sessions.
  3. Installing SelectorsHub in any supported browser say chrome
  4. Inspect any element and go to SelectorsHub tab to auto-generate the XPath Expressions, CSS Selectors and other locators too.

Arun Motoori

Comments (0)

Leave a Reply

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

For FREE Testing Tutorials & Videos

Open chat
Contact Us on Whatsapp