For the complete documentation index, see llms.txt. This page is also available as Markdown.

Wait

Type: wait

The wait action tells the browser to pause for a specified time or until a particular element appears on the page.

Tips for using wait action
  • Wait for a selector rather than a fixed time wherever you can. It moves on as soon as the element appears.

  • Never set both time and selector. If you do, time wins and the timeout is ignored completely.

  • Set continue_on_fail: true when the element you're waiting for might not appear.

  • You don't need a wait before click, capture_element or parse_table, since they wait for their own selectors.

  • A fixed time is still the right choice for animations settling or for slowing a sequence down on purpose.

Parameters

Parameter Requirements: You must provide either time or selector.

Name
Type
Description

time

integer

The time in milliseconds the browser should wait.

selector

string

The selector for the element to wait for.

timeout

integer

The maximum time in milliseconds to wait for selector to appear. Default: 5,000 (5s).

Usage

Wait for a particular amount of time

The following code will wait 1 second, then continue to the next action.

Wait 1 second:

"actions": [
      {
        "type": "wait",
        "time": 1000
      }
]

Wait for a particular element to appear

The following code will wait for a table to appear on the page for up to 5 seconds. If the table has not appeared after 5 seconds, the next action will be executed.

Wait for table to appear:

timeout is shown explicitly above for clarity, but it isn't required. Leaving it out gives you the same 5-second wait:

FAQs

When do I use the wait action?

Use it when you need to pause between actions — waiting for content to load after a click, for an animation to finish, or for a slow page to finish rendering before you capture it.

How do I wait for an element to appear?

Add a wait action with a selector for the element. Gaffa waits up to 5 seconds by default and continues as soon as the element appears, or set timeout to change how long it waits.

How do I pause for a fixed amount of time?

Add a wait action with time set in milliseconds. Use this for animations or deliberate pacing, rather than for content that might take a variable amount of time to load.

Should I wait for a selector or a fixed time?

Use a selector when you can, because it waits only until the element appears. A fixed time always waits the full duration, so save it for first calls when you don’t know the page structure yet.

What happens if I set both time and selector?

time takes over and timeout is ignored. The browser moves on once the time is up, whether or not the element appeared. Use one or the other, never both.

Should I wait for a selector or a fixed time?

Wait for a selector where you can. It moves on as soon as the element exists, instead of always using the full time, which makes sequences quicker and more reliable.

What if the element never appears?

The action fails once the timeout is up, and by default the request stops. Set continue_on_fail: true if the element is optional and the rest should still run.

Do I need to set a timeout when using selector?

No. timeout defaults to 5,000ms if you leave it out. Set it explicitly only when you want a shorter or longer wait than that.

Do I need a wait before every capture?

No. Add one only when the content loads after the previous action finishes. click, capture_element and parse_table already wait for their own selectors.

Last updated