Function raceSelectors

  • Races multiple waitForSelector calls and returns the first successful result along with the selector that won.

    Parameters

    • ctx: Context

      The Puppeteer context or page to use for selector operations.

    • selectors: [string, ...string[]]

      An array of selectors to race.

    • Optionaloptions: WaitForSelectorOptions

      Optional configuration for waitForSelector.

    Returns Promise<{
        result: null | ElementHandle<Node>;
        winner: string;
    }>

    A promise that resolves to an object containing:

    • result: The result of the first successful waitForSelector call.
    • winner: The selector that won the race.

    If no selectors are provided.

    const result = await raceSelectors(page, ['#btn1', '#btn2', '#btn3']);
    console.log(result); // { result: <ElementHandle>, winner: '#btn1' }