Skip to content

Query reference

Queries read state rather than mutating the page. Most run against a Locator; url and title run against the Page.

url (Page)

The current page URL.

1
$page.url;        # 'file:///path/to/hello.html'

title (Page)

The document title.

1
$page.title;      # 'Hello'

text-content

The element's textContent.

1
$page.locator('#greeting').text-content;   # 'Hello, world'

inner-text

The rendered innerText, reflecting visibility and CSS.

1
$page.locator('#greeting').inner-text;      # 'Hello, world'

get-attribute

The value of a named attribute, or the type object when absent.

1
$page.locator('#name').get-attribute('type');   # 'text'

input-value

The current value of an input, textarea, or select.

1
$page.locator('#name').input-value;

count

The number of elements the locator matches.

1
$page.locator('#color option').count;       # 3

is-visible, is-enabled, is-checked

Boolean state checks.

1
2
3
$page.locator('#greeting').is-visible;       # True
$page.locator('#name').is-enabled;           # True
$page.locator('#agree').is-checked;          # False until checked

wait-for

Waits until the element reaches a state: attached, detached, visible, or hidden.

1
$page.locator('#greeting').wait-for(state => 'visible');

Chaining

locator chains from a page or another locator, scoping the selector to the parent.

1
$page.locator('body').locator('#greeting').text-content;