Basic Locator Practice

This level helps you master every Selenium locator individually before moving to CSS Selectors and XPath.

ID Locator Practice

Practice the following:

  • Locate the username field using ID.
  • Locate the password field using ID.
  • Locate the login button using ID.
  • Validate element presence using ID.
  • Practice locating an element when the ID is not unique and observe the behavior.

Name Locator Practice

Practice the following:

Advertisement
  • Locate an input field using Name.
  • Locate a radio button using Name.
  • Locate a checkbox using Name.
  • Locate a submit button using Name.
  • Handle multiple elements having the same Name attribute.

ClassName Locator Practice

Practice the following:

  • Locate an element using a single class.
  • Locate an element having multiple classes and observe the failure.
  • Fix the locator by selecting the correct class.
  • Identify reusable classes across multiple pages.
  • Verify the limitations of the ClassName locator.

TagName Locator Practice

Practice the following:

  • Locate all input elements.
  • Count all hyperlinks using the a tag.
  • Count all buttons on a page.
  • Iterate through elements using TagName.
  • Extract text from all labels.

LinkText Practice

Practice the following:

  • Locate a link using complete LinkText.
  • Click Login.
  • Click Register.
  • Click Forgot Password.
  • Verify link navigation.
  • Practice case-sensitive LinkText.
  • Handle link text changes.

PartialLinkText Practice

Practice the following:

  • Locate a link using PartialLinkText.
  • Handle dynamic link text.
  • Identify links even when the text changes.
  • Compare LinkText with PartialLinkText.
  • Fix flaky LinkText locators.

CSS Selector Exercises

Basic CSS Selector Practice

Practice locating elements using:

  • tag#id
  • tag.class
  • Multiple classes
  • Attribute selector
  • Attribute with value

Advanced CSS Selector Practice

Practice:

  • Starts With (^=)
  • Ends With ($=)
  • Contains (*=)
  • Child selector (>)
  • Descendant selector (space)

Real-Time CSS Scenarios

Practice the following:

  • Convert XPath to CSS Selector.
  • Choose CSS instead of XPath and justify the decision.
  • Fix a broken CSS locator.
  • Handle dynamic attributes using CSS.
  • Validate CSS selector performance.

XPath Exercises

Absolute vs Relative XPath

Practice the following:

  • Create an Absolute XPath for the Login button.
  • Create a Relative XPath.
  • Break the Absolute XPath and observe the failure.
  • Fix the broken XPath.
  • Explain which XPath is used in your project.

XPath Functions Practice

Practice:

  • contains()
  • starts-with()
  • text()

Also practice:

  • Handling dynamic text.
  • Fixing flaky XPath expressions.

XPath Operators Practice

Practice using:

  • AND
  • OR

Also practice:

  • Combining multiple attributes.
  • Handling optional attributes.
  • Validating correct element selection.

XPath Axes Practice (Most Important)

Practice:

  • parent
  • child
  • following
  • preceding
  • following-sibling
  • preceding-sibling
  • ancestor

Also practice:

  • Table row and column handling.
  • Dynamic lists.
  • Nested elements.

Real-Time Application Scenarios

Login Page Exercises

Practice locating:

  • Username using a dynamic ID.
  • Password without ID or Name.
  • Login button using surrounding text.
  • Elements relative to labels.
  • Error messages.

Dynamic Element Handling

Practice:

  • Dynamic IDs.
  • Dynamic class names.
  • Auto-generated attributes.
  • Identifying stable attributes.
  • Creating future-proof locators.

UI Change Scenarios

Practice:

  • Fixing broken locators after UI changes.
  • Updating locators after text changes.
  • Handling additional wrapper DIVs.
  • Refining locators after duplicate elements appear.
  • Optimizing heavy XPath expressions.

Framework-Level Exercises

Practice the following:

  1. Store locators inside a Page Object.
  2. Refactor duplicate locators.
  3. Apply locator naming conventions.
  4. Debug locator failures using logs.
  5. Review and improve a teammate's locator strategy.

Interview Capstone Tasks

Practice the following interview scenarios:

  1. Automate login using the best locator strategy.
  2. Identify and replace weak locators.
  3. Convert Absolute XPath into Relative XPath.
  4. Convert XPath into CSS Selector.
  5. Optimize locators for speed and stability.
  6. Justify locator selection during interviews.
  7. Explain a fallback locator strategy.
  8. Debug a NoSuchElementException.
  9. Handle a StaleElementReferenceException.
  10. Design the locator strategy for an entire page.

Best Demo Websites for Locator Practice

SauceDemo

Website: saucedemo.com

Practice:

  • Login page automation.
  • ID, Name, ClassName.
  • XPath.
  • CSS Selectors.
  • Dynamic locator behavior.

OrangeHRM Demo

Website: opensource-demo.orangehrmlive.com

Practice:

  • Enterprise UI.
  • Dynamic IDs.
  • Advanced XPath.
  • Real project locator strategies.

Automation Practice

Website: automationpractice.com

Practice:

  • LinkText.
  • PartialLinkText.
  • Product listings.
  • Text-based XPath.

Rahul Shetty Practice

Website: rahulshettyacademy.com/AutomationPractice/

Practice:

  • XPath Axes.
  • Parent and Child.
  • Following and Preceding.
  • Tables.
  • Checkbox handling.

DemoQA

Website: demoqa.com

Practice:

  • Dynamic elements.
  • Nested DOM.
  • Modern UI structures.

Site-Mapped Practice Exercises

SauceDemo Login Practice

Practice:

  • Username using ID.
  • Password using ID.
  • Login button using ID.
  • Username using Name.
  • Login button using ClassName.
  • Locate all inputs using TagName.
  • Login button using CSS Selector.
  • Login button using XPath.
  • Break the ID locator and fix it using XPath.
  • Explain why ID is the best locator in this case.

OrangeHRM Dynamic ID Practice

Practice:

  • Locate Username without using ID.
  • Handle changing attribute values.
  • Use contains().
  • Use starts-with().
  • Identify stable attributes.
  • Locate elements using label text.
  • Fix broken locators after refresh.
  • Explain why ID should be avoided.
  • Practice AND conditions.
  • Create future-proof locators.

DemoQA Absolute vs Relative XPath

Practice:

  • Create an Absolute XPath for the Submit button.
  • Execute the test.
  • Break the DOM.
  • Observe Absolute XPath failure.
  • Create a Relative XPath.
  • Compare stability.
  • Explain which approach should be used in projects.

Automation Practice LinkText Exercises

Practice:

  • Locate the "Women" link using LinkText.
  • Locate the same link using PartialLinkText.
  • Change the link text.
  • Observe locator failure.
  • Fix using XPath.
  • Decide the best locator.

Rahul Shetty CSS Selector Practice

Practice:

  • Checkbox using CSS.
  • Attribute selectors.
  • Contains selector.
  • Child selector.
  • Descendant selector.
  • Compare CSS with XPath.
  • Fix broken CSS locators.
  • Optimize CSS selectors.
  • Explain CSS performance.
  • Explain CSS strategy during interviews.

OrangeHRM XPath Function Practice

Practice:

  • contains() for Username.
  • starts-with() for Password.
  • text() for Login button.
  • Dynamic text handling.
  • Multiple attributes.
  • AND conditions.
  • OR conditions.
  • Validate the correct element.
  • Fix flaky XPath.
  • Create reusable XPath expressions.

Rahul Shetty XPath Axes Practice

Practice:

  • Parent axis.
  • Child axis.
  • Following axis.
  • Preceding axis.
  • Following-Sibling axis.
  • Preceding-Sibling axis.
  • Ancestor axis.
  • Table row and column handling.
  • Checkbox relative to text.
  • Explain XPath Axes during interviews.

Real-Time UI Change Practice

Practice all five UI change scenarios described in the Real-Time Application Scenarios section using any of the recommended demo websites.


Framework-Level Practice

Practice using SauceDemo or OrangeHRM:

  • Store locators in Page Objects.
  • Rename locators clearly.
  • Remove duplicate locators.
  • Review teammate locator strategies.
  • Explain your locator strategy during interviews.

FAQs

What order should I practice Selenium locators?

Practice in this order:

  • Basic locators
  • CSS Selectors
  • XPath Functions
  • XPath Operators
  • XPath Axes
  • Real-Time Scenarios
  • Interview Capstone

Why should I intentionally break locators?

Breaking locators helps you understand failure scenarios and improves debugging skills required in real-world projects and interviews.


Which website is best for XPath Axes?

Rahul Shetty Practice provides excellent examples for Parent, Child, Following, Sibling, and Table-based XPath Axes.


Which website is best for practicing dynamic IDs?

OrangeHRM Demo provides enterprise-style applications with dynamic IDs and changing attributes.


What is the final interview-level exercise?

Design a complete locator strategy for an entire page, including primary locators, fallback locators, optimization, and justification.