Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Teamcapybara Capybara Node Actions Click Button

From Leeroopedia
Knowledge Sources
Domains Testing, Form_Interaction
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for submitting forms by clicking buttons provided by Capybara::Node::Actions#click_button.

Description

Node::Actions#click_button delegates to find(:button, locator, **options).click. The :button selector matches multiple HTML elements: <button>, <input type="submit">, <input type="reset">, <input type="button">, <input type="image">, and elements with role="button" (when enable_aria_role is true). Locator matches against id, name, test_id, value, title, or visible text.

Usage

Call after filling in form fields. The locator should match the button's visible text or value attribute.

Code Reference

Source Location

  • Repository: capybara
  • File: lib/capybara/node/actions.rb
  • Lines: L57-59

Signature

def click_button(locator = nil, **options)
  # @param locator [String, nil] Button text, id, name, test_id, value, or title
  # @param options [Hash] Standard find options (disabled:, id:, name:, class:, wait:)
  # @return [Capybara::Node::Element] The clicked button element
  find(:button, locator, **options).click
end

Import

require 'capybara'

I/O Contract

Inputs

Name Type Required Description
locator String/nil No Button text, value, id, name, or title
disabled Boolean/Symbol No Match disabled buttons (:all for both)
wait Numeric No Override wait time

Outputs

Name Type Description
element Capybara::Node::Element The clicked button element

Usage Examples

Click Buttons

click_button 'Submit'
click_button 'Save Changes'
click_button 'Delete', class: 'btn-danger'

Full Form Example

within('#registration-form') do
  fill_in 'Name', with: 'Alice'
  fill_in 'Email', with: 'alice@example.com'
  select 'United States', from: 'Country'
  check 'I agree to terms'
  click_button 'Register'
end

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment