Click
Type: click
Request that the browser click a particular element on the page.
Parameters
timeout
integer
The maximum amount of time the browser should wait for the element defined by the selector to appear. Default: 5000 (5s)
See universal parameters.
Usage
Click an element on the page
The following clicks the page logo.
"actions": [
{
"type": "click",
"selector": "a.header__logo"
}
]Click an element when it appears
The following waits up to 5 seconds for the logo to appear, then clicks it. It continues if the click fails.
FAQs
When do I use the click action?
Use it whenever you need the browser to interact with something — a button, a link, a tab, a checkbox, or a "load more" control. Anything a user would click.
How do I click a button with Gaffa?
Add a click action with a CSS selector for the button. Gaffa waits up to five seconds for it to appear before clicking. Change that with the timeout parameter.
What selector should I use for a click?
Use something stable like id, data-testid or aria-label. Generated class names and positional selectors like nth-child break as soon as the site changes.
How do I close a cookie banner before scraping a page?
Add a click for the accept button with continue_on_fail: true, before your other actions. That flag stops the request failing on pages where the banner doesn't show.
How do I wait for content to load after a click?
Follow the click with a wait action using a selector that only exists in the new content, plus a timeout. That's more reliable than waiting a fixed number of seconds.
Why did my click fail?
Usually the selector didn't match in time, or the element was there but covered by a pop-up. Capture the DOM to check the selector, and close any overlay first.
Last updated