Good
Product card → Add to cart şeklinde scope-then-act yap.QA PRACTICE•REPEATED
Lesson 11 / 20 · Intermediate
Scope cards, rows, and nested controls precisely.
12 min
Not completed
Tekrarlayan kart, satır veya listede önce container’ı bul, sonra onun içinde kontrolü ara. `filter({ hasText, has })` ilişkiyi korur; global aynı isimli butonun nth’ine güvenmez.
Prerequisites: Role and accessible name
Live demo
Try the locator against the live demo.
Product card → Add to cart şeklinde scope-then-act yap.Global `getByRole('button', {name:'Add to cart'}).nth(1)` kullanma.Kart sırası değişse bile ürün adı ile aksiyon ilişkisi korunur.
Sadece kart metninin eşleşmesi, kart içindeki butonun da doğru olduğu anlamına gelmez; nested kontrolü ayrıca seç.
page.locator("[data-testid='repeated-demo'] li:nth-of-type(2) button")driver.findElement(By.cssSelector("[data-testid='repeated-demo'] li:nth-of-type(2) button"))cy.get("[data-testid='repeated-demo'] li:nth-of-type(2) button")