Skip to main content
  • Decorator
  • Direct Function Call (Callable Pattern)
  • Wrapper Function Pattern
def wait_for_dom_settled(
    func: Callable[[Page], Any] | Callable[[Locator], Any] | None,
    *,
    settle_duration: float,
    timeout_s: float,
)
Decorator that waits for DOM mutations to settle after executing the decorated function.This helper uses a MutationObserver to monitor DOM changes and waits until the DOM has been stable (no mutations) for the specified settle_duration. Essential for handling dynamic content that’s added/modified via JavaScript after user interactions.Use this decorator for actions that trigger DOM changes:
  • Clicking buttons that dynamically add content
  • Infinite scroll implementations
  • Waiting for loading spinners to disappear
  • Dynamic tables/lists being populated
  • Client-side routing animations

Examples

from intuned_browser import wait_for_dom_settled
async def automation(page, params, **_kwargs):
    await page.goto("https://example.com")
    # Decorator without arguments (uses settle_duration=0.5, timeout_s=30.0)
    @wait_for_dom_settled
    async def load_more_content(page):
        await page.locator("button.load-more").click()
    # Automatically waits for DOM to settle after clicking
    await load_more_content(page)
    # DOM has settled, new content is loaded

Arguments

func
Callable[[Page], Any] | Callable[[Locator], Any]
required
The async function to decorate. Must accept a Page or Locator object as a parameter. If not provided, returns a parameterized decorator.
settle_duration
float
default:"0"
Duration in seconds that the DOM must remain stable (no mutations) to be considered “settled”. Increase for slow animations. Defaults to 0.5.
timeout_s
float
default:"30"
Maximum seconds to wait for DOM to settle before timing out. Raises an error if timeout is reached. Defaults to 30.0.

Returns: Callable

The decorated function that waits for DOM to settle after execution.
  • The decorated function MUST have a page or source parameter (or receive a Locator)
  • Can monitor entire page (Page) or specific elements (Locator)
  • DOM is “settled” when no mutations occur for settle_duration seconds
  • Raises error on timeout (unlike wait_for_network_settled which logs warning)
  • Use Locator to ignore unrelated DOM changes on other parts of the page