×
☰ See All Chapters

Puppeteer waitFor method

  • waitFor waits for certain amount of time before resolving.  

  •  

waitFor(duration: number): Promise<void>

waitFor Example

import { launch, Page } from 'puppeteer';

example();

async function example() {

    const browser = await launch( { headless: false } );

    const page = await browser.newPage();

    await page.goto( 'https://www.registration.tools4testing.com/' );

    await page.waitFor(5000);

    await browser.close();

}

This has be overridden to provide shortcut for waitForSelector and waitForXPath

waitFor(selector: string, options: WaitForSelectorOptionsHidden): Promise<ElementHandle | null>;

waitFor(selector: string, options?: WaitForSelectorOptions): Promise<ElementHandle>;

waitForFileChooser(options?: Timeoutable): Promise<FileChooser>

In non-headless Chromium, this method results in the native file picker dialog not showing up for the user. This method is typically coupled with an action that triggers file choosing. This must be called before the file chooser is launched. It will not return a currently active file chooser.

waitForNavigation(options?: NavigationOptions): Promise<Response>

 

Wait for the page navigation to occur.

waitForRequest( urlOrPredicate: string | ((req: Request) => boolean), options?: Timeoutable): Promise<Request>

urlOrPredicate:  A URL or predicate to wait for.

Options:  Optional timeout parameter. This is the maximum time puppeteer wait for the request.

waitForResponse(urlOrPredicate: string | ((res: Response) => boolean), options?: Timeoutable): Promise<Response>;

urlOrPredicate:  A URL or predicate to wait for.

Options:  Optional timeout parameter. This is the maximum time puppeteer wait for the response.

 


All Chapters
Author