Skip to main content
Wait for elements, JavaScript conditions, and network requests before proceeding with automation.

Methods

page.waitForSelector()

Waits for an element matching the selector to appear in the DOM.
Parameters:
  • selector: CSS selector for the element to wait for
  • options (optional): Wait options
Options:
Returns: Promise<void> Examples:

page.waitForFunction()

Waits until a function returns a truthy value.
Parameters:
  • fn: Function to evaluate repeatedly until it returns truthy
  • options (optional): Wait options
  • args (optional): Arguments to pass to the function
Returns: Promise<void> Examples:

page.waitForRequest()

Waits for a matching HTTP request to occur.
Parameters:
  • matcher: URL string or predicate function to match requests
  • options (optional): Wait options
RequestMatchFunction:
Returns: Promise<Request> - The matched request Examples:

Complete examples

Wait for page load

Wait for dynamic content

Wait for API response

Sequential waits

Timeout handling

Wait for multiple conditions

Wait for text content

Poll for changes

Wait for network idle

Best practices

Wait for elements before clicking or typing:
Set timeouts based on expected load times:
Always catch timeout errors gracefully:
Wait for several conditions to ensure page is ready:

Navigation

Navigate and track page loads

Events

Monitor page events

Interaction

Interact after waiting

Page overview

Back to Page API overview