Skip to main content
Glama

click_element

Click element(s) matching a CSS, XPath, or supported text selector.

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: - nth is 1-based and takes precedence over every other click mode. - Otherwise, all_matches=True clicks every currently visible match. - Otherwise, only_if_visible=True clicks only if a match is visible. - Otherwise, parent_selector scopes 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 if provided. 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 any of the click actions induces page navigation, then
    subsequent clicks are cancelled without any exceptions raised.

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 the first button: click_element("button") - Click the 2nd button: click_element("button", nth=2) - Click all checkboxes: click_element('input[type="checkbox"]', all_matches=True) - Click the first visible link: click_element("a", only_if_visible=True) - Click the first button that's inside the first iframe: click_element("button", parent_selector="iframe")

Error behavior: With the exception of using 'only_if_visible=True', if there's no matching element found within the timeout, then @handle_sb_errors returns details from the exception raised.

When not to use: - Do not use this tool if you need to hover an element first before clicking; use hover_action with action="hover_and_click" instead.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nthNo
scrollNo
timeoutNo
selectorYes
all_matchesNo
only_if_visibleNo
parent_selectorNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv1.3.3

TDQS

A4.7/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden, and it does well: it discloses that all_matches clicks are cancelled without exceptions if navigation occurs, that only_if_visible does not wait, that timeout is ignored by conditional/bulk modes, and that errors are routed through @handle_sb_errors. It doesn't explicitly state that clicks are destructive/irreversible, but for a click tool the mutation is self-evident and the navigation-cancellation caveat is valuable. A 4 is warranted; a 5 would require even more operational detail like exact exception types or side effects on page state.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long but every section earns its place: selection behavior, per-parameter semantics, examples, error behavior, and when-not-to-use. It is well-structured with headers and bullet-like formatting, and the most important scoping rule (nth precedence) is front-loaded. It loses one point only because the length is substantial and some parameter explanations could be tightened without losing clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 7-parameter tool with no annotations and 0% schema coverage, the description is remarkably complete. It covers all parameters, precedence, error behavior, and exclusions, and provides five examples covering each mode. The output schema exists, so return-value documentation is not required. Nothing an agent needs to invoke this tool correctly is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must fully compensate, and it does. Every parameter (selector, nth, all_matches, only_if_visible, parent_selector, timeout, scroll) is explained with semantics, precedence, defaults, and constraints. It even warns that text-matching selectors are unsupported with all_matches=True. This is far beyond what the bare schema provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb and resource: 'Click element(s) matching a CSS, XPath, or supported text selector.' It then enumerates the distinct click modes (normal, nth, all_matches, only_if_visible, parent-scoped), which clearly differentiates it from sibling tools like hover_action, focus_element, and select_option. The examples further cement what the tool does.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description includes an explicit 'When not to use' section that names hover_action as the alternative for hover-then-click flows. It also gives clear selection-behavior precedence rules (nth > all_matches > only_if_visible > parent_selector > normal), so an agent knows exactly when to set which parameter. This is exemplary usage guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.