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) -> None

Example

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

click

MethodSince v0.0.14

Clicks the first matching element. ClickOptions accepts left, middle, or right button and a click_count from 1 to 3.

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

dblclick

MethodSince v0.1.25

Double-clicks the first matching element with the selected mouse button.

def dblclick(self, selector: str, options: ClickOptions | CommandOptions | None = None) -> None

fill

MethodSince v0.0.14

Sets an input/textarea's value.

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

hover

MethodSince v0.0.14

Hovers the pointer over the matching element.

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

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) -> None

focus

MethodSince v0.0.14

Focuses the first matching element.

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

highlight

MethodSince v0.0.14

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

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

count

MethodSince v0.0.14

Returns how many elements match selector.

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

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) -> str | None
def inner_text(self, selector: str, options: CommandOptions | None = None) -> str

Example

heading = page.text_content(HEADING_SELECTOR)
print(heading)

url

MethodSince v0.1.14

Reads the page's current URL — for a frame page, the frame document's URL.

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

Example

current = page.url()

input_value / is_checked / get_attribute

MethodSince v0.1.14

Read the first match's state: the live value of an input, textarea, or select; the checked state of a native or ARIA checkbox/radio (ARIA mixed reads as False); or an attribute — None when it's missing, "" when it's present but empty. A missing element or an incompatible control raises AllwrightError.

def input_value(self, selector: str, options: CommandOptions | None = None) -> str
def is_checked(self, selector: str, options: CommandOptions | None = None) -> bool
def get_attribute(self, selector: str, name: str, options: CommandOptions | None = None) -> str | None

Example

value = page.locator("input[name=email]").input_value()
checked = page.locator("input[type=checkbox]").is_checked()
href = page.locator("a").get_attribute("href")

selected_options / selected_text

MethodSince v0.1.14

selected_options reads a native select (including multiple selection) or an ARIA listbox/combobox's aria-selected="true" options. selected_text reads the textbox's selected substring — "" for a bare caret, None for input types that don't support selection.

def selected_options(self, selector: str, options: CommandOptions | None = None) -> list[CapturedOption]
def selected_text(self, selector: str, options: CommandOptions | None = None) -> str | None

@dataclass
class CapturedOption:
    value: str
    label: str
    index: int

bounding_box

MethodSince v0.1.14

Reads the first match's box in CSS pixels, relative to the page or frame viewport. Returns None for a hidden or zero-area element.

def bounding_box(self, selector: str, options: CommandOptions | None = None) -> BoundingBox | None

@dataclass
class BoundingBox:
    x: float
    y: float
    width: float
    height: float

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) -> None

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) -> bytes

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]

frame

MethodSince v0.1.13

Resolves the single iframe matching selector to a Page once its document has loaded and settled. Same as page.locator(selector).frame(options) — see Locator.frame.

def frame(self, selector: str, options: CommandOptions | None = None) -> Page