Methods
page.waitForSelector()
Waits for an element matching the selector to appear in the DOM.
selector: CSS selector for the element to wait foroptions(optional): Wait options
Promise<void>
Examples:
page.waitForFunction()
Waits until a function returns a truthy value.
fn: Function to evaluate repeatedly until it returns truthyoptions(optional): Wait optionsparameters(optional): Parameters to pass to the function
Promise<void>
Examples:
page.waitForRequest()
Waits for a matching HTTP request to occur.
matcher: URL string or predicate function to match requestsoptions(optional): Wait options
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
Always wait before interacting
Always wait before interacting
Wait for elements before clicking or typing:
Use appropriate timeouts
Use appropriate timeouts
Set timeouts based on expected load times:
Handle timeout errors
Handle timeout errors
Always catch timeout errors gracefully:
Wait for multiple indicators
Wait for multiple indicators
Wait for several conditions to ensure page is ready: