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) -> NoneExample
page.goto("https://themoderninternet.vercel.app")click
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) -> Nonedblclick
Double-clicks the first matching element with the selected mouse button.
def dblclick(self, selector: str, options: ClickOptions | CommandOptions | None = None) -> Nonefill
Sets an input/textarea's value.
def fill(self, selector: str, value: str, options: CommandOptions | None = None) -> Nonehover
Hovers the pointer over the matching element.
def hover(self, selector: str, options: CommandOptions | None = None) -> Nonepress
Presses a keyboard key, optionally typing PressOptions.text, on the matching element.
def press(self, selector: str, key: str, options: PressOptions | None = None) -> Nonefocus
Focuses the first matching element.
def focus(self, selector: str, options: CommandOptions | None = None) -> Nonehighlight
Visually highlights matching elements for a duration — a debugging aid.
def highlight(self, selector: str, options: HighlightOptions | None = None) -> Nonecount
Returns how many elements match selector.
def count(self, selector: str, options: CommandOptions | None = None) -> inttext_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) -> str | None
def inner_text(self, selector: str, options: CommandOptions | None = None) -> strExample
heading = page.text_content(HEADING_SELECTOR)
print(heading)url
Reads the page's current URL — for a frame page, the frame document's URL.
def url(self, options: CommandOptions | None = None) -> strExample
current = page.url()input_value / is_checked / get_attribute
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 | NoneExample
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
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: intbounding_box
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: floatwait_for_selector
Waits, retrying, until selector matches — optionally requiring visible=True.
def wait_for_selector(self, selector: str, options: WaitForSelectorOptions | None = None) -> NoneExample
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) -> bytesaccessibility_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]frame
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