Skip to content
Release: Australia · Updated: 2026-06-25 · Official documentation · View source

screen — DOM queries

The screen API is the primary interface for finding elements on the page tested by a Run UI Test Script step. All query methods pierce shadow roots automatically, so they work with Now Experience components as well as classic Jelly and UI16 pages.

Query method variants

Each query type comes in the following variants.

VariantReturnsThrows when missing?Async?
getBy*Single elementYes, throws immediatelyNo
getAllBy*Array of elementsYes, if emptyNo
queryBy*Single element or nullNoNo
queryAllBy*Array, which may be emptyNoNo
findBy*Single elementYes, rejects the PromiseYes, polls until found
findAllBy*Array of elementsYes, if emptyYes, polls until found

Use findBy* when the element appears asynchronously, such as after an API response, animation, or navigation. Use getBy* when the element must already exist. Use queryBy* to check whether an element is absent.

Query types

Each variant supports the following query types.

TypeFinds elements byExample
RoleARIA role, implicit or explicitscreen.getByRole('button', { name: 'Save' })
TextVisible text contentscreen.findByText('Incident created')
LabelTextAssociated <label> textscreen.getByLabelText('Short description')
PlaceholderTextplaceholder attributescreen.getByPlaceholderText('Search…')
AltTextalt attributescreen.getByAltText('Company logo')
Titletitle attributescreen.getByTitle('Close dialog')
TestIddata-testid attributescreen.getByTestId('submit-btn')
DisplayValueCurrent display value of a form controlscreen.getByDisplayValue('High')
SelectorCSS selector, shadow-piercingscreen.getBySelector('input[name="priority"]')

getByRole is the recommended default because it validates accessibility as it queries. Use getBySelector only when no accessible query matches.

screen.waitFor(callback, options?)

Polls callback until it stops throwing. Use this method to wait for a condition that isn't directly an element query.

await screen.waitFor(() => {
  expect(screen.getByRole('status')).toHaveTextContent('Complete');
});

Options: { timeout: 5000, interval: 50 }, in milliseconds.

screen.debug(element?)

Logs the outer HTML of element, or the whole page body when omitted, to the browser console, including shadow root contents. Use it when a query doesn't match what you expect.

screen.debug(); // log the full page
screen.debug(screen.getByRole('form')); // log a specific subtree

Shadow DOM traversal

All screen.getBy*, screen.findBy*, and screen.queryBy* queries automatically pierce shadow roots. Now Experience components render their content inside shadow roots, which are normally invisible to document.querySelector. The ATF testing library traverses these boundaries transparently, so you can query by role or text whether the element is in light DOM or shadow DOM.

getByRole resolves accessible names by reading shadow root text content when the host element's own text content is empty, matching the behavior that a screen reader reports.

getBySelector uses a custom shadow-piercing CSS selector engine that handles cross-shadow combinators, for example now-typeahead input.