Case Study: Locator Chaining in Selenium WebDriver

Cleaner and more readable locators in Selenium tests with Locator Chaining

Zhimin Zhan
6 min readJan 16, 2023

--

A repost of my daughter’s article with permission. I added a few notes. This is also included in my “How to in Selenium WebDriver” series.

Locator Chaining, in test automation, is a way to find an element relative to another. I will illustrate how to use locator chaining with a real example in this article.

Table of Contents:
· One Selenium Test Failed
·
Analyse
·
The Problem — Multiple Elements
·
The Solution — Locator Chaining
1. Find all matching elements
2. Filter for displayed elements
3. Get the first displayable notification badge
4. Use Locator Chaining to go back to the parent elements
·
Zhimin’s notes

One Selenium Test Failed

This test (for my fathers’ WhenWise app) is to verify if a group training is available on Saturday, marked with the number in a red circle.

--

--

Zhimin Zhan

Test automation & CT coach, author, speaker and award-winning software developer. Help teams succeed with Agile/DevOps by implementing real Continuous Testing.