Skip to main content
Page provides methods to interact with a single tab in a browser. Each page has a main frame and can have child frames.

Inheritance

Extends: ChannelOwner Implements: EventEmitter

Events

  • load: Emitted when the load event is fired
  • domcontentloaded: Emitted when DOMContentLoaded event is fired
  • close: Emitted when page is closed
  • crash: Emitted when page crashes
  • console: Emitted when console message is logged
  • dialog: Emitted when a dialog appears
  • download: Emitted when download starts
  • filechooser: Emitted when file chooser opens
  • frameattached: Emitted when frame is attached
  • framedetached: Emitted when frame is detached
  • framenavigated: Emitted when frame navigates
  • pageerror: Emitted when uncaught exception occurs
  • popup: Emitted when popup is opened
  • request: Emitted when request is made
  • response: Emitted when response is received
  • requestfailed: Emitted when request fails
  • requestfinished: Emitted when request finishes
  • websocket: Emitted when WebSocket is created
  • worker: Emitted when worker is created

Properties

keyboard

Keyboard
Keyboard input instance.

mouse

Mouse
Mouse input instance.

touchscreen

Touchscreen
Touchscreen input instance.

request

APIRequestContext
API request context.

clock

Clock
Clock instance for time control.

coverage

Coverage
Coverage instance (Chromium only).

goto

Navigates to a URL.
string
required
URL to navigate to
GotoOptions
Navigation options
  • timeout (number): Maximum time in milliseconds
  • waitUntil (‘load’ | ‘domcontentloaded’ | ‘networkidle’ | ‘commit’): When to consider navigation succeeded
  • referer (string): Referer header value
Returns: Promise<Response | null> - Main resource response

reload

Reloads the page.
ReloadOptions
Reload options (same as goto)
Returns: Promise<Response | null> - Main resource response

goBack

Navigates to the previous page in history.
NavigationOptions
Navigation options
Returns: Promise<Response | null> - Main resource response

goForward

Navigates to the next page in history.
NavigationOptions
Navigation options
Returns: Promise<Response | null> - Main resource response

waitForNavigation

Waits for navigation to finish.
WaitForNavigationOptions
Wait options
  • url (string | RegExp): URL pattern to wait for
  • waitUntil (string): When to consider navigation succeeded
  • timeout (number): Maximum wait time
Returns: Promise<Response | null> - Response

waitForLoadState

Waits for load state to be reached.
string
Load state to wait for (default: ‘load’)
TimeoutOptions
Timeout options
Returns: Promise<void>

waitForURL

Waits for page to navigate to matching URL.
string | RegExp
required
URL pattern to wait for
WaitForURLOptions
Wait options
Returns: Promise<void>

Selector Methods

$

Finds an element matching the selector.
string
required
Selector to query
object
  • strict (boolean): Throw if multiple elements match
Returns: Promise<ElementHandle | null> - Element handle or null

$$

Finds all elements matching the selector.
string
required
Selector to query
Returns: Promise<ElementHandle[]> - Array of element handles

locator

Creates a locator.
string
required
Selector to locate
LocatorOptions
Locator options
  • hasText (string | RegExp): Matches elements containing text
  • hasNotText (string | RegExp): Matches elements not containing text
  • has (Locator): Matches elements containing another locator
  • hasNot (Locator): Matches elements not containing another locator
Returns: Locator - Locator instance

getByRole

Creates a locator by ARIA role.
string
required
ARIA role
ByRoleOptions
Role options
Returns: Locator - Locator instance

getByText

Creates a locator by text content.
string | RegExp
required
Text to match
object
  • exact (boolean): Exact match
Returns: Locator - Locator instance

getByLabel

Creates a locator by label text.
string | RegExp
required
Label text to match
object
  • exact (boolean): Exact match
Returns: Locator - Locator instance

getByPlaceholder

Creates a locator by placeholder text.
string | RegExp
required
Placeholder text to match
object
  • exact (boolean): Exact match
Returns: Locator - Locator instance

getByAltText

Creates a locator by alt text.
string | RegExp
required
Alt text to match
object
  • exact (boolean): Exact match
Returns: Locator - Locator instance

getByTitle

Creates a locator by title attribute.
string | RegExp
required
Title to match
object
  • exact (boolean): Exact match
Returns: Locator - Locator instance

getByTestId

Creates a locator by test ID.
string | RegExp
required
Test ID to match
Returns: Locator - Locator instance

Action Methods

click

Clicks an element.
string
required
Selector to click
ClickOptions
Click options
  • button (‘left’ | ‘right’ | ‘middle’): Mouse button
  • clickCount (number): Number of clicks
  • delay (number): Delay between mousedown and mouseup
  • position (object): Click position
  • modifiers (string[]): Modifier keys
  • force (boolean): Force click even if element is not actionable
  • noWaitAfter (boolean): Don’t wait for navigation
  • timeout (number): Maximum time in milliseconds
Returns: Promise<void>

dblclick

Double clicks an element.

fill

Fills an input field.
string
required
Selector to fill
string
required
Value to fill
FillOptions
Fill options
Returns: Promise<void>

type

Types text into an element.
string
required
Selector to type into
string
required
Text to type
TypeOptions
Type options
  • delay (number): Delay between key presses in milliseconds
  • timeout (number): Maximum time
Returns: Promise<void>

press

Presses a key.
string
required
Selector to focus
string
required
Key to press (e.g., ‘Enter’, ‘ArrowDown’)
PressOptions
Press options
Returns: Promise<void>

check

Checks a checkbox.

uncheck

Unchecks a checkbox.

selectOption

Selects options in a <select> element.
string
required
Selector to select from
string | string[] | SelectOption | SelectOption[]
required
Values to select
SelectOptionOptions
Select options
Returns: Promise<string[]> - Array of selected values

hover

Hovers over an element.

tap

Taps an element (mobile).

dragAndDrop

Drags and drops an element.
string
required
Source element selector
string
required
Target element selector
DragAndDropOptions
Drag options
Returns: Promise<void>

Content Methods

content

Returns page HTML content.
Returns: Promise<string> - Full HTML content

setContent

Sets page HTML content.
string
required
HTML content to set
SetContentOptions
Set content options
Returns: Promise<void>

title

Returns page title.
Returns: Promise<string> - Page title

url

Returns page URL.
Returns: string - Current URL

textContent

Returns element’s text content.

innerText

Returns element’s inner text.

innerHTML

Returns element’s inner HTML.

getAttribute

Returns element’s attribute value.

State Methods

isVisible

Checks if element is visible.

isHidden

Checks if element is hidden.

isEnabled

Checks if element is enabled.

isDisabled

Checks if element is disabled.

isChecked

Checks if checkbox is checked.

isEditable

Checks if element is editable.

Evaluation Methods

evaluate

Evaluates JavaScript in page context.
Function | string
required
Function to evaluate
any
Argument to pass to function
Returns: Promise<R> - Evaluation result

evaluateHandle

Evaluates and returns a JSHandle.

$eval

Evaluates function on an element.

$$eval

Evaluates function on multiple elements.

Frame Methods

mainFrame

Returns the main frame.
Returns: Frame - Main frame

frames

Returns all frames.
Returns: Frame[] - Array of frames

frame

Finds a frame by name or URL.
string | object
required
Frame name or URL pattern
Returns: Frame | null - Matching frame or null

frameLocator

Creates a frame locator.
string
required
Frame selector
Returns: FrameLocator - Frame locator instance

Utility Methods

screenshot

Takes a screenshot.
ScreenshotOptions
Screenshot options
  • path (string): File path to save to
  • type (‘png’ | ‘jpeg’): Image type
  • quality (number): JPEG quality (0-100)
  • fullPage (boolean): Capture full page
  • clip (object): Clip area
  • omitBackground (boolean): Transparent background
  • timeout (number): Maximum time
  • mask (Locator[]): Elements to mask
Returns: Promise<Buffer> - Screenshot buffer

pdf

Generates a PDF.
PDFOptions
PDF options
  • path (string): File path to save to
  • format (string): Paper format (e.g., ‘A4’)
  • width (string | number): Paper width
  • height (string | number): Paper height
  • margin (object): Page margins
  • printBackground (boolean): Print background graphics
  • landscape (boolean): Landscape orientation
Returns: Promise<Buffer> - PDF buffer

close

Closes the page.
object
  • runBeforeUnload (boolean): Run beforeunload handlers
  • reason (string): Close reason
Returns: Promise<void>

isClosed

Checks if page is closed.
Returns: boolean - True if closed

context

Returns the browser context.
Returns: BrowserContext - Parent context

opener

Returns the opener page.
Returns: Promise<Page | null> - Opener page or null

bringToFront

Brings page to front.
Returns: Promise<void>

setViewportSize

Sets viewport size.
object
required
Viewport dimensions
  • width (number): Width in pixels
  • height (number): Height in pixels
Returns: Promise<void>

viewportSize

Returns viewport size.
Returns: object | null - Viewport size or null

setDefaultTimeout

Sets default timeout.
number
required
Timeout in milliseconds

setDefaultNavigationTimeout

Sets default navigation timeout.
number
required
Timeout in milliseconds

workers

Returns all workers.
Returns: Worker[] - Array of workers

Usage Examples

Basic Page Automation

Using Locators

Form Interactions