Skip to main content
Glama

Click Element

click_element

Click webpage elements using CSS, XPath, or text selectors, with options for nth match, all visible matches, conditional visibility, or parent-scoped clicks.

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 and priority: 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. If none of the above are set, then a regular click is performed.

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. Addedv4.54.3

TDQS

A5/5.0
Behavior5/5

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

Beyond the annotations, it discloses subtle runtime behavior: the priority order of selection modes, that all_matches cancels subsequent clicks if page navigation occurs, that only_if_visible does not wait for visibility, and the timeout/error handling behavior. This is exactly the kind of context an agent needs beyond readOnly/openWorld flags.

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

Conciseness5/5

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

Although substantial, every section contributes: purpose, selection priority, per-argument detail, examples, error behavior, and anti-guidance. It is organized with clear headers and front-loaded with the core action.

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?

Given the rich parameter set and no parameter documentation in the schema, the description covers selection modes, defaults, exclusions, error behavior, and example calls. The presence of an output schema means return-value documentation is already handled, so nothing essential 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?

With 0% schema coverage, the description carries the full parameter burden and does so thoroughly. It defines selector types, explains nth precedence and 1-based indexing, clarifies all_matches cancellation, notes timeout default and non-use in conditional/bulk modes, and documents parent_selector iframe support.

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?

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 (nth, all matches, conditional, parent-scoped), which clearly separates it from sibling tools like hover_action or focus_element.

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 'When not to use' section explicitly routes hover-before-click scenarios to hover_action, and the description repeatedly states the intended use cases: normal, indexed, bulk, conditional, and parent-scoped clicks. This gives an agent clear decision rules.

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