Here's a hard truth: 80% of flaky tests are caused by bad locators. You write a test, it works today, it fails tomorrow — nobody changed the test code. What happened? The developer renamed a CSS class, moved a div, or the framework generated a new random ID. Your locator broke.
This chapter teaches you to write locators that survive UI changes. You'll master CSS selectors, XPath expressions, and learn the decision framework for choosing the right strategy every time. By the end, you'll write locators like a senior — short, stable, and readable.
Locator questions come up in every Selenium interview. "CSS vs XPath?", "How do you handle dynamic IDs?", "How do you locate an element with no ID?" — this chapter gives you real answers with real examples.
Key Point: Bad locators = flaky tests. This chapter teaches you to write locators that don't break when the UI changes.