click
Click web elements by CSS, XPath, or text selector. Handle nth match, all visible matches, visibility conditions, or clicks scoped to a parent container.
Instructions
Click element(s) matching a CSS, XPath, or supported text selector.
Use this tool for normal clicks, clicking a specific matching occurrence, clicking all visible matches, conditional clicks, or clicks scoped to a parent element.
Selection behavior:
nthis 1-based and takes precedence over every other click mode.Otherwise,
all_matches=Trueclicks every currently visible match.Otherwise,
only_if_visible=Trueclicks only if a match is visible.Otherwise,
parent_selectorscopes the click to a nested element.With none of the above, performs a normal SeleniumBase click.
Args:
selector: CSS selector, XPath selector, or supported SeleniumBase
text-matching selector. Text-matching selectors such as
a:contains("Sign in") are supported only for single-element
clicks; do not use them with all_matches=True.
nth: 1-based occurrence to click when multiple elements match.
Must be >= 1. Takes precedence over `all_matches`,
`only_if_visible`, and `parent_selector`.
all_matches: If True, click every currently visible matching element
in order of appearance. Ignored when `nth` is provided. Use only
when multiple clicks are intentionally desired, such as for
clicking all the checkboxes in a section of a webpage.
If a click induces page navigation, then subsequent clicks are
cancelled.
only_if_visible: If True, click only when the target is already
visible; do not wait for it to become visible.
parent_selector: CSS/XPath selector for the parent/container in which
to find `selector`. Used only for the nested-click mode.
Can be used to click an element inside a parent iframe.
timeout: Maximum seconds to wait for a normal click operation.
Default: 5. Not used by conditional or bulk click modes.
scroll: If True, scroll the target into view before a normal or
indexed click. Default: True.Examples:
- Click one element: click("button.submit")
- Click the 2nd matching element: click("button", nth=2)
- Click all visible matches: click(".dismiss", all_matches=True)
- Click only if already visible: click("#menu", only_if_visible=True)
- Click inside a container: click(".item", parent_selector="#result")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nth | No | ||
| scroll | No | ||
| timeout | No | ||
| selector | Yes | ||
| all_matches | No | ||
| only_if_visible | No | ||
| parent_selector | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |