Wait
Type: wait
The wait action tells the browser to pause for a specified time or until a particular element appears on the page.
Parameters
time
integer
The time in milliseconds the browser should wait.
timeout
integer
The maximum time in milliseconds to wait for selector to appear. Default: 5,000 (5s).
See universal parameters.
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