Principle:Teamcapybara Capybara Form Field Filling
| Knowledge Sources | |
|---|---|
| Domains | Testing, Form_Interaction |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
A form interaction pattern that locates text fields or text areas by accessible identifiers and sets their values.
Description
Form Field Filling combines element finding and value setting into a single semantic operation. Instead of manually finding a field and calling set, this pattern uses the :fillable_field selector to locate inputs by name, id, test_id, placeholder, or label text — matching how real users identify form fields. The pattern:
- Finds the field using the :fillable_field selector with the given locator
- Optionally filters by current value (currently_with option)
- Calls set on the found element with the provided value and driver-specific fill options
This approach is resilient to DOM structure changes because it uses semantic identifiers rather than CSS selectors.
Usage
Use this for any text input or textarea interaction. Prefer fill_in over find(:field).set as it provides better error messages and semantic matching.
Theoretical Basis
# Abstract fill_in flow (not actual code)
fill_in(locator, with: value):
element = find(:fillable_field, locator)
element.set(value, **fill_options)
return element