Implementation:Teamcapybara Capybara Node Actions Selection
| Knowledge Sources | |
|---|---|
| Domains | Testing, Form_Interaction |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tools for interacting with select boxes, checkboxes, and radio buttons provided by Capybara::Node::Actions.
Description
Node::Actions#select finds a select box (or datalist input) using from: and selects an option by text. #check and #uncheck use _check_with_label (L364-384) which tries set(true/false) on the element; if the element is not interactable and automatic_label_click is enabled, it clicks the associated label instead. #choose follows the same pattern for radio buttons.
Usage
Call these methods with the control's label text, name, or id as the locator.
Code Reference
Source Location
- Repository: capybara
- File: lib/capybara/node/actions.rb
- Lines: L201-211 (select), L150-152 (check), L178-180 (uncheck), L122-124 (choose)
Signature
def select(value = nil, from: nil, **options)
# @param value [String] Option text to select
# @param from [String] Label/name/id of the select box
# @return [Capybara::Node::Element]
end
def check(locator = nil, **options)
# @param locator [String] Label/name/id of the checkbox
# @option options [String] option Value attribute of checkbox
# @option options [Boolean, Hash] allow_label_click Click label if element non-visible
# @return [Capybara::Node::Element]
end
def uncheck(locator = nil, **options)
# Same params as check
# @return [Capybara::Node::Element]
end
def choose(locator = nil, **options)
# @param locator [String] Label/name/id of the radio button
# @option options [String] option Value attribute of radio button
# @return [Capybara::Node::Element]
end
Import
require 'capybara'
# Available via Capybara::DSL or on any Node instance
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| value (select) | String | No | Option text to select |
| from (select) | String | No | Label/name/id of the select box |
| locator | String | No | Label/name/id of checkbox or radio |
| option | String | No | Value attribute to match |
| allow_label_click | Boolean/Hash | No | Click label if element hidden (default: automatic_label_click config) |
Outputs
| Name | Type | Description |
|---|---|---|
| element | Capybara::Node::Element | The interacted element or clicked label |
Usage Examples
Select Dropdown
select 'March', from: 'Month'
select 'United States', from: 'Country'
Checkboxes
check 'I agree to terms'
uncheck 'Subscribe to newsletter'
check 'Red', allow_label_click: true
Radio Buttons
choose 'Male'
choose 'Credit Card', option: 'cc'