No video
Page locators are the better way to select elements in Playwright
Playwright offers different ways to select and access elements. Learn in this video why page locators ("page.locator") are preferred over element handles ("page.$").
Find more information in the Playwright documentation: playwright.dev/docs/locators#...
#playwright
Пікірлер: 10
Thanks a lot it was very helpful🙏
@ChecklyHQ
Жыл бұрын
Most welcome 😊
awesome! Thanks a lot!
@ChecklyHQ
Жыл бұрын
Happy it was useful!
I have a question about name of locators. If I have some locator which has different id (mn-235425 - some random numbers), how can I ignore numeric part?
@ChecklyHQ
Жыл бұрын
Hello Nikolay, you could use a CSS attribute selector in your locator - `const button = page.locator("[id^=mn-]")`. But keep in mind that it's best practice to select elements based on user-facing characteristics such as text or role to test "real" user behavior. Hope this helps. 🦝
what does one dollar vs 2 dollar signs do?
@ChecklyHQ
8 ай бұрын
`page.$` selects one whereas `page.$$` selects all elements in the page. That said, both methods are deprecated now and you should favor `page.locator` or the user-first locators (`page.getByRole`). Hope this helps. :)
And what's the equivalent of $$ with the locators
@stefanjudis
Жыл бұрын
If I'm not mistaken, `page.locator` should work with the same selectors as `page.$$`. :)