docs(selectors): avoid nth, first, last (#16028)

This commit is contained in:
Ross Wollman 2022-07-28 13:17:18 -07:00 committed by GitHub
parent 4b7da07b0f
commit 5a91623fae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1323,7 +1323,7 @@ await page.Locator("data-test-id=directions").ClickAsync();
### Avoid selectors tied to implementation
[xpath] and [css] can be tied to the DOM structure or implementation. These selectors can break when
the DOM structure changes.
the DOM structure changes. Similarly, [`method: Locator.nth`], [`method: Locator.first`], and [`method: Locator.last`] are tied to implementation and the structure of the DOM, and will target the incorrect element if the DOM changes.
```js
// avoid long css or xpath chains