Skip to main content
Repeatedly click a button until no new content appears or max clicks reached. This function is useful for “Load More” buttons or paginated content where you need to keep clicking until all content is loaded. It provides several stopping conditions:
  • Button becomes invisible/disabled
  • Maximum number of clicks reached
  • No change detected in container content (when containerLocator is provided)
export declare function clickUntilExhausted(input: {
  page: Page;
  buttonLocator: Locator;
  heartbeat?: CallableFunction;
  containerLocator?: Locator;
  maxClicks?: number;
  clickDelay?: number;
  noChangeThreshold?: number;
}): Promise<void>;

Examples

import { clickUntilExhausted } from "@intuned/browser";
import { BrowserContext, Page } from "playwright";

interface Params {}

export default async function handler(
  params: Params,
  page: Page,
  context: BrowserContext
) {
  await page.goto("https://sandbox.intuned.dev/load-more");
  const loadMoreButton = page.locator("main main button"); // Select the main button in the main content area.

  // Click until button disappears or is disabled
  await clickUntilExhausted({
    page,
    buttonLocator: loadMoreButton,
    maxClicks: 20,
  });
  // Will keep clicking the button until the button disappears or is disabled or the maxClicks is reached.
}

Arguments

input
Object
required
Configuration options

Returns: Promise<void>

Promise that resolves when clicking is exhausted