# class: Locator * since: v1.14 Locators are the central piece of Playwright's auto-waiting and retry-ability. In a nutshell, locators represent a way to find element(s) on the page at any moment. A locator can be created with the [`method: Page.locator`] method. [Learn more about locators](../locators.md). ## async method: Locator.all * since: v1.29 - returns: <[Array]<[Locator]>> When the locator points to a list of elements, this returns an array of locators, pointing to their respective elements. :::note [`method: Locator.all`] does not wait for elements to match the locator, and instead immediately returns whatever is present in the page. When the list of elements changes dynamically, [`method: Locator.all`] will produce unpredictable and flaky results. When the list of elements is stable, but loaded dynamically, wait for the full list to finish loading before calling [`method: Locator.all`]. ::: **Usage** ```js for (const li of await page.getByRole('listitem').all()) await li.click(); ``` ```python async for li in await page.get_by_role('listitem').all(): await li.click(); ``` ```python sync for li in page.get_by_role('listitem').all(): li.click(); ``` ```java for (Locator li : page.getByRole("listitem").all()) li.click(); ``` ```csharp foreach (var li in await page.GetByRole("listitem").AllAsync()) await li.ClickAsync(); ``` ## async method: Locator.allInnerTexts * since: v1.14 - returns: <[Array]<[string]>> Returns an array of `node.innerText` values for all matching nodes. :::warning[Asserting text] If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] with [`option: LocatorAssertions.toHaveText.useInnerText`] option to avoid flakiness. See [assertions guide](../test-assertions.md) for more details. ::: **Usage** ```js const texts = await page.getByRole('link').allInnerTexts(); ``` ```python async texts = await page.get_by_role("link").all_inner_texts() ``` ```python sync texts = page.get_by_role("link").all_inner_texts() ``` ```java String[] texts = page.getByRole(AriaRole.LINK).allInnerTexts(); ``` ```csharp var texts = await page.GetByRole(AriaRole.Link).AllInnerTextsAsync(); ``` ## async method: Locator.allTextContents * since: v1.14 - returns: <[Array]<[string]>> Returns an array of `node.textContent` values for all matching nodes. :::warning[Asserting text] If you need to assert text on the page, prefer [`method: LocatorAssertions.toHaveText`] to avoid flakiness. See [assertions guide](../test-assertions.md) for more details. ::: **Usage** ```js const texts = await page.getByRole('link').allTextContents(); ``` ```python async texts = await page.get_by_role("link").all_text_contents() ``` ```python sync texts = page.get_by_role("link").all_text_contents() ``` ```java String[] texts = page.getByRole(AriaRole.LINK).allTextContents(); ``` ```csharp var texts = await page.GetByRole(AriaRole.Link).AllTextContentsAsync(); ``` ## method: Locator.and * since: v1.34 * langs: - alias-python: and_ - returns: <[Locator]> Creates a locator that matches both this locator and the argument locator. **Usage** The following example finds a button with a specific title. ```js const button = page.getByRole('button').and(page.getByTitle('Subscribe')); ``` ```java Locator button = page.getByRole(AriaRole.BUTTON).and(page.getByTitle("Subscribe")); ``` ```python async button = page.get_by_role("button").and_(page.getByTitle("Subscribe")) ``` ```python sync button = page.get_by_role("button").and_(page.getByTitle("Subscribe")) ``` ```csharp var button = page.GetByRole(AriaRole.Button).And(page.GetByTitle("Subscribe")); ``` ### param: Locator.and.locator * since: v1.34 - `locator` <[Locator]> Additional locator to match. ## async method: Locator.ariaSnapshot * since: v1.49 - returns: <[string]> Captures the aria snapshot of the given element. Read more about [aria snapshots](../aria-snapshots.md) and [`method: LocatorAssertions.toMatchAriaSnapshot`] for the corresponding assertion. **Usage** ```js await page.getByRole('link').ariaSnapshot(); ``` ```java page.getByRole(AriaRole.LINK).ariaSnapshot(); ``` ```python async await page.get_by_role("link").aria_snapshot() ``` ```python sync page.get_by_role("link").aria_snapshot() ``` ```csharp await page.GetByRole(AriaRole.Link).AriaSnapshotAsync(); ``` **Details** This method captures the aria snapshot of the given element. The snapshot is a string that represents the state of the element and its children. The snapshot can be used to assert the state of the element in the test, or to compare it to state in the future. The ARIA snapshot is represented using [YAML](https://yaml.org/spec/1.2.2/) markup language: * The keys of the objects are the roles and optional accessible names of the elements. * The values are either text content or an array of child elements. * Generic static text can be represented with the `text` key. Below is the HTML markup and the respective ARIA snapshot: ```html