allwright

API ReferencePythonPage

Page

Page.locator(selector) returns a Locator scoped to a selector, which exposes the same action methods below plus the semantic builders and filters documented under Locator.

goto

MethodSince v0.0.14

Navigates the page to a URL. navigate() is an alias.

def goto(self, url: str, options: CommandOptions | None = None) -> NavigateResult

Example

page.goto("https://themoderninternet.vercel.app")

click

MethodSince v0.0.14

Clicks the first element matching selector.

def click(self, selector: str, options: CommandOptions | None = None) -> ClickResult

fill

MethodSince v0.0.14

Sets an input/textarea's value.

def fill(self, selector: str, value: str, options: CommandOptions | None = None) -> FillResult

hover

MethodSince v0.0.14

Hovers the pointer over the matching element.

def hover(self, selector: str, options: CommandOptions | None = None) -> ElementResult

press

MethodSince v0.0.14

Presses a keyboard key, optionally typing PressOptions.text, on the matching element.

def press(self, selector: str, key: str, options: PressOptions | None = None) -> PressResult

focus

MethodSince v0.0.14

Focuses the first matching element.

def focus(self, selector: str, options: CommandOptions | None = None) -> ElementResult

highlight

MethodSince v0.0.14

Visually highlights matching elements for a duration — a debugging aid.

def highlight(self, selector: str, options: HighlightOptions | None = None) -> HighlightResult

count

MethodSince v0.0.14

Returns how many elements match selector.

def count(self, selector: str, options: CommandOptions | None = None) -> CountResult

text_content / inner_text

MethodSince v0.0.14

Reads the raw textContent, or the rendered inner_text, of the matching element.

def text_content(self, selector: str, options: CommandOptions | None = None) -> TextResult

Example

heading = page.text_content(HEADING_SELECTOR)
heading.text

wait_for_selector

MethodSince v0.0.14

Waits, retrying, until selector matches — optionally requiring visible=True.

def wait_for_selector(self, selector: str, options: WaitForSelectorOptions | None = None) -> WaitForSelectorResult

Example

page.wait_for_selector('xpath=//h1[text()="Form Inputs"]')

screenshot

MethodSince v0.0.54 – v0.0.55

Captures a PNG screenshot; full_page captures the whole scrollable page, and path writes the PNG to disk.

def screenshot(self, options: ScreenshotOptions | None = None) -> ScreenshotResult

accessibility_snapshot

MethodSince v0.1.1

Captures the accessibility tree as JSON or YAML text. options.mode selects "default", "ai" (stable per-node reference), "autoexpect", or "codegen".

def accessibility_snapshot(self, options: AccessibilitySnapshotOptions | None = None) -> str

Example

page.accessibility_snapshot(AccessibilitySnapshotOptions(format="yaml", mode="ai"))

locator

MethodSince v0.0.33

Builds a Locator scoped to this page for a raw CSS/XPath selector, or use the get_by_* semantic builders documented under Locator.

def locator(self, selector: str) -> Locator

register_hook

MethodSince v0.1.5

Registers a lifecycle hook before the action that triggers it.

def register_hook(self, hook_type: HookType[T]) -> Hook[T]