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
Navigates the page to a URL. navigate() is an alias.
def goto(self, url: str, options: CommandOptions | None = None) -> NavigateResultExample
page.goto("https://themoderninternet.vercel.app")click
Clicks the first element matching selector.
def click(self, selector: str, options: CommandOptions | None = None) -> ClickResultfill
Sets an input/textarea's value.
def fill(self, selector: str, value: str, options: CommandOptions | None = None) -> FillResulthover
Hovers the pointer over the matching element.
def hover(self, selector: str, options: CommandOptions | None = None) -> ElementResultpress
Presses a keyboard key, optionally typing PressOptions.text, on the matching element.
def press(self, selector: str, key: str, options: PressOptions | None = None) -> PressResultfocus
Focuses the first matching element.
def focus(self, selector: str, options: CommandOptions | None = None) -> ElementResulthighlight
Visually highlights matching elements for a duration — a debugging aid.
def highlight(self, selector: str, options: HighlightOptions | None = None) -> HighlightResultcount
Returns how many elements match selector.
def count(self, selector: str, options: CommandOptions | None = None) -> CountResulttext_content / inner_text
Reads the raw textContent, or the rendered inner_text, of the matching element.
def text_content(self, selector: str, options: CommandOptions | None = None) -> TextResultExample
heading = page.text_content(HEADING_SELECTOR)
heading.textwait_for_selector
Waits, retrying, until selector matches — optionally requiring visible=True.
def wait_for_selector(self, selector: str, options: WaitForSelectorOptions | None = None) -> WaitForSelectorResultExample
page.wait_for_selector('xpath=//h1[text()="Form Inputs"]')screenshot
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) -> ScreenshotResultaccessibility_snapshot
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) -> strExample
page.accessibility_snapshot(AccessibilitySnapshotOptions(format="yaml", mode="ai"))locator
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) -> Locatorregister_hook
Registers a lifecycle hook before the action that triggers it.
def register_hook(self, hook_type: HookType[T]) -> Hook[T]