QA PRACTICE•BRITTLE

Locator Practice HubTopics / Repair brittle locators

Lesson 19 / 20 · Intermediate

Repair brittle locators

Replace indexes and absolute XPath with resilient alternatives.

10 min

Not completed

Concept

Kırık locator onarımında önce davranış contract’ını bul, sonra gereksiz wrapper/index/class parçalarını at. Before/after diff ile değişen CSS’i değil stabil hedefi görünür kıl.

Prerequisites: Dynamic elements, Repeated components

Live demo

Try the locator

Scoped to lesson demo

Try the locator against the live demo.

Good

Role/label/testid veya scoped stable attribute’a indirgeme yap.

Avoid

Absolute XPath’i sadece bekleme ekleyerek yaşatmaya çalışma.

Why

Daha kısa locator her zaman iyi değildir; önemli olan değişimlerden bağımsız anlamlı anchor’dır.

Real-world trap

Kısa olan her selector stabil değildir; `.button` de globalde çok geniş olabilir.

Framework comparison

Playwright

page.locator("[data-testid='repair-action']")

Selenium

driver.findElement(By.cssSelector("[data-testid='repair-action']"))

Cypress

cy.get("[data-testid='repair-action']")

Mini quiz

Brittle locator onarımında ilk adım nedir?