Queries
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.
$page.url; # 'file:///path/to/hello.html'
title (Page)#
The document title.
$page.title; # 'Hello'
text-content#
The element's textContent.
$page.locator('#greeting').text-content; # 'Hello, world'
inner-text#
The rendered innerText, reflecting visibility and CSS.
$page.locator('#greeting').inner-text; # 'Hello, world'
get-attribute#
The value of a named attribute, or the type object when absent.
$page.locator('#name').get-attribute('type'); # 'text'
input-value#
The current value of an input, textarea, or select.
$page.locator('#name').input-value;
count#
The number of elements the locator matches.
$page.locator('#color option').count; # 3
is-visible, is-enabled, is-checked#
Boolean state checks.
$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.
$page.locator('#greeting').wait-for(state => 'visible');
Chaining#
locator chains from a page or another locator, scoping the selector to the
parent.
$page.locator('body').locator('#greeting').text-content;