--- title: screen and Locator description: "API reference for the screen fixture and Locator in e2e, with queries, refinement, actions, reads, and the match rules." "og:image": "https://e2e.com/docs/images/og/reference/screen.png?v=1b21c45d37" "twitter:image": "https://e2e.com/docs/images/og/reference/screen.png?v=1b21c45d37" --- The `screen` fixture builds locators. A `Locator` stores a query and resolves it when an action, read, or assertion runs. Every query also runs on a locator, scoped to its subtree. ```ts title="tests/invoices.e2e.ts" import { expect, test } from 'e2e'; test('void an invoice', async ({ app, screen }) => { await app.open('/invoices'); const row = screen.getByRole('listitem').filter({ hasText: 'Invoice 42' }); await row.getByRole('button', 'Void').tap(); await expect(row.getByText('Voided')).toBeVisible(); }); ``` ## Reference ### Queries | Method | Returns | | --- | --- | | [`getByRole`](#getbyrole) | `Locator` | | [`getByLabel`](#getbylabel) | `Locator` | | [`getByPlaceholder`](#getbyplaceholder) | `Locator` | | [`getByText`](#getbytext) | `Locator` | | [`getByDisplayValue`](#getbydisplayvalue) | `Locator` | | [`getByTestId`](#getbytestid) | `Locator` | Every query returns a `Locator` synchronously and performs no work. An option key the query does not take (`{ nam: 'Save' }`) throws `INVALID_LOCATOR` naming the keys it does. A string passed to `getByRole` as the name, `getByLabel`, `getByPlaceholder`, `getByText`, or `getByDisplayValue` matches the whole text, case-sensitive, after whitespace normalization: `getByRole('button', 'Save')` does not match `Save changes`. `{ exact: false }` makes it a case-insensitive substring match, and a `RegExp` matches as written. Every query accepts `visible: true`; see [Hidden duplicates](#hidden-duplicates). #### `getByRole` Matches nodes by [role](#types), optionally narrowed to an accessible name and to states. ```ts getByRole(role: Role | RoleAlias, options?: RoleOptions): Locator; getByRole(role: Role | RoleAlias, name: TextMatch, options?: Omit): Locator; ``` ```ts screen.getByRole('button', 'Save'); screen.getByRole('button', 'Save', { exact: false }); screen.getByRole('button', { name: 'Save', disabled: true }); // the object form screen.getByRole('heading', /welcome/i, { level: 1 }); ``` The accessible name goes second, a string or a `RegExp`, with the other options after it. The object form, `{ name: 'Save' }`, is the same query. The options are [`RoleOptions`](#types): `pressed` is the pressed state of a toggle button, and `level` is a heading level, 1 through 6. For visible content inside an unlabelled list item or status, filter by text, for example `screen.getByRole('listitem').filter({ hasText: 'Invoice 42' })`. A role query never matches a node hidden from the accessibility tree: one that does not render, or one under `aria-hidden`. On the other query kinds, `visible: true` keeps only nodes that render, the same check `toBeVisible()` makes, so an `aria-hidden` node that still paints counts as visible. See [Hidden duplicates](#hidden-duplicates). On a device or a desktop app a role query skips every node the engine marks hidden, which can include one scrolled out of view: see [mobile](/reference/mobile#visibility) and [desktop](/reference/desktop#visibility) for what each marks. ##### `img` alias `img` is an alias, not a role ([`RoleAlias`](#types)). `getByRole('img', { name })` builds the same query as `getByRole('image', { name })`. On the web, `image` covers `` with alt text and any element with `role="img"`. An `` is decoration and matches nothing, unless it has a `title`, a `tabindex`, or a global ARIA attribute: then it is an `image`. ##### Roles on the web The web engine derives the roles from HTML the way HTML-AAM does: - `` is `progressbar`, `` is `meter`, `
` is `separator`. - `
` and `
` are `group`. - `` is `spinbutton`. `` is `button`. - `` naming a `` is a `combobox`. - A `` of a `role="grid"` table is a `gridcell`. - `` and `` are `rowgroup`. - `` is `rowheader`. A scope-less `` beside a data cell with text or children is also a `rowheader`; header-only rows keep `columnheader`. A lone scope-less header in a one-row table has no header role, but an explicit `scope="col"` or `scope="colgroup"` keeps `columnheader`. - `
` is `figure`, `
` is `article`. - `
` and `