page.$$(selector)
Warning
When possible, use locator-based
page.locator(selector)
instead.However, using
locator
s may not always work when selecting an element from a list or table, especially if there isn’t a reliable way to consistently identify a single element (for example, due to changing or non-unique attributes). In such cases,$$
remains useful.
The method finds all elements matching the specified selector within the page. If no elements match the selector, the return value resolves to []
. This is particularly useful when you want to retrieve a list of elements, and iterate through them to find the one that you need for your test case.