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 container_locator is provided)
async def click_until_exhausted(
    page: Page,
    button_locator: Locator,
    heartbeat: Callable[[], None],
    *,
    container_locator: Locator | None,
    max_clicks: int,
    click_delay: float,
    no_change_threshold: int,
)

Examples

from typing import TypedDict
from playwright.async_api import Page
from intuned_browser import click_until_exhausted
class Params(TypedDict):
    pass
async def automation(page: Page, params: Params, **_kwargs):
    await page.goto("https://sandbox.intuned.dev/load-more")
    load_more_button = page.locator("main main button")  # Select the main button in the main content area.
    # Click until button disappears or is disabled
    await click_until_exhausted(
        page=page,
        button_locator=load_more_button,
        max_clicks=20
    )
    # Will keep clicking the button until the button disappears or is disabled or the max_clicks is reached.

Arguments

page
Page
required
Playwright Page object
button_locator
Locator
required
Locator for the button to click repeatedly
heartbeat
Callable[[], None]
Optional callback invoked after each click. Defaults to lambda: None.
container_locator
Locator
Optional content container to detect changes. Defaults to None.
max_clicks
int
Maximum number of times to click the button. Defaults to 50.
click_delay
float
Delay after each click (in seconds). Defaults to 0.5.
no_change_threshold
int
Minimum change in content size to continue clicking. Defaults to 0.

Returns: None

Function completes when clicking is exhausted