Implementation:Teamcapybara Capybara Node Element Interaction
| Knowledge Sources | |
|---|---|
| Domains | Testing, DOM_Interaction |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tools for clicking, setting values, and sending keystrokes to elements provided by Capybara::Node::Element.
Description
Node::Element#click delegates to base.click via perform_click_action which handles modifier keys and coordinate offsets within a synchronize block. Node::Element#set merges default_set_options with provided options and delegates to base.set. Node::Element#send_keys directly delegates to base.send_keys. All three return self for method chaining.
Usage
Call on a found element: find(:button, 'Submit').click, find(:field, 'Name').set('Alice'), find(:field, 'Search').send_keys('query', :enter).
Code Reference
Source Location
- Repository: capybara
- File: lib/capybara/node/element.rb
- Lines: L170-174 (click), L117-125 (set), L274-277 (send_keys)
Signature
def click(*keys, **options)
# @param *keys [Symbol] Modifier keys: :alt, :control, :meta, :shift
# @option options [Integer] x Click offset X
# @option options [Integer] y Click offset Y
# @option options [Float] delay Delay between mousedown/mouseup
# @return [Capybara::Node::Element]
end
def set(value, **options)
# @param value [String] New value for the form element
# @param **options [Hash] Driver-specific options (merged with default_set_options)
# @return [Capybara::Node::Element]
end
def send_keys(*args)
# @param *args [String, Symbol, Array] Keys to send
# @return [Capybara::Node::Element]
end
Import
require 'capybara'
# Methods available on any Capybara::Node::Element instance
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| keys (click) | Symbol(s) | No | Modifier keys held during click |
| x, y (click) | Integer | No | Click offset coordinates |
| value (set) | String | Yes | Value to set on the form element |
| args (send_keys) | String/Symbol/Array | Yes | Keys to send |
Outputs
| Name | Type | Description |
|---|---|---|
| self | Capybara::Node::Element | The element itself (for chaining) |
Usage Examples
Click Interactions
find(:button, 'Submit').click
find(:link, 'Delete').click(:control) # Ctrl+Click
find('#canvas').click(x: 100, y: 50) # Click at offset
# Right-click and double-click
find('#menu-trigger').right_click
find('#item').double_click
Set Values
find(:field, 'Email').set('user@example.com')
find(:field, 'Password').set('secret', clear: :backspace)
Send Keys
find(:field, 'Search').send_keys('capybara', :enter)
find('#editor').send_keys([:control, 'a'], :delete)