Implementation:Teamcapybara Capybara Node Actions Fill In
| Knowledge Sources | |
|---|---|
| Domains | Testing, Form_Interaction |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for filling in text fields and text areas provided by Capybara::Node::Actions#fill_in.
Description
Node::Actions#fill_in uses find(:fillable_field, locator, **find_options) to locate the input, then calls .set(with, **fill_options) on it. The :fillable_field selector matches text inputs, password inputs, email inputs, textareas, and other fillable elements by their name, id, test_id attribute, placeholder, or associated label text. The currently_with option filters fields by their current value.
Usage
Call fill_in with a locator identifying the field and a with: keyword for the desired value.
Code Reference
Source Location
- Repository: capybara
- File: lib/capybara/node/actions.rb
- Lines: L88-92
Signature
def fill_in(locator = nil, with:, currently_with: nil, fill_options: {}, **find_options)
# @param locator [String, nil] Name, id, test_id, placeholder, or label text
# @param with [String] The value to fill in (required keyword)
# @param currently_with [String, nil] Match field by current value
# @param fill_options [Hash] Driver-specific options (e.g., { clear: :backspace })
# @param find_options [Hash] Options passed to find(:fillable_field, ...)
# @return [Capybara::Node::Element] The filled element
find_options[:with] = currently_with if currently_with
find_options[:allow_self] = true if locator.nil?
find(:fillable_field, locator, **find_options).set(with, **fill_options)
end
Import
require 'capybara'
# fill_in available via Capybara::DSL or on any Node instance
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| locator | String/nil | No | Field identifier (name, id, test_id, placeholder, label text) |
| with | String | Yes | Value to fill in |
| currently_with | String | No | Match field by its current value |
| fill_options | Hash | No | Driver-specific options (e.g., { clear: :backspace }) |
| id | String/Regexp | No | Match by id attribute |
| name | String | No | Match by name attribute |
| placeholder | String | No | Match by placeholder attribute |
| class | String/Array/Regexp | No | Match by CSS class |
Outputs
| Name | Type | Description |
|---|---|---|
| element | Capybara::Node::Element | The filled-in form element |
Usage Examples
Basic Fill In
fill_in 'Name', with: 'Alice'
fill_in 'Email', with: 'alice@example.com'
fill_in 'Password', with: 'secret123'
With Options
# Match by current value
fill_in 'Username', with: 'new_name', currently_with: 'old_name'
# Driver-specific clear method
fill_in 'Search', with: 'query', fill_options: { clear: :backspace }
# Without locator (operates on self)
find(:field, 'Name').fill_in(with: 'Bob')