Spotted something off?Report on Discord
guides

Wait For Selector

Pause browser execution until a specific CSS selector appears in the DOM, with optional timeout and error handling.

Updated May 28, 2025

Pause execution until a specific element appears in the DOM β€” ideal for waiting on AJAX content, modal windows, or any dynamically loaded section.

Command

"wait_for_selector"

This action waits until a particular CSS selector appears on the page. It's useful for synchronization and ensuring elements are present before interacting with them.

Parameters

Parameter Type Required Description
cssSelector string Yes The CSS selector to wait for. Example: [class='col']
timeout number No Time in milliseconds to wait before timing out. Default is system-defined. Example: 30000
when string No When to run the check: "beforeload" or "afterload". Default is "afterload".
ignoreErrors boolean No Set to true to continue even if the selector is not found.

Example

bash13 lines

Notes

Use Case Ideas:

  • Wait for content to load after an AJAX call before scraping.
  • Detect when modals or confirmation boxes appear before clicking.
  • Ensure dynamic tables or product listings are fully rendered.

Tips:

  • Use wait_for_selector before actions like click, type, or solve_captcha.
  • Combine with ignoreErrors: true if the element may not always appear, but scraping should continue.