Method: Capybara::Node::Actions#fill_in

Defined in:
lib/capybara/node/actions.rb

#fill_in([locator], with: , **options) ⇒ Capybara::Node::Element

Locate a text field or text area and fill it in with the given text. The field can be found via its name, id, test_id attribute, placeholder, or label text. If no locator is provided this will operate on self or a descendant.

# will fill in a descendant fillable field with name, id, or label text matching 'Name'
page.fill_in 'Name', with: 'Bob'

# will fill in `el` if it's a fillable field
el.fill_in with: 'Tom'

If the driver is capable of executing JavaScript, this method will wait for a set amount of time and continuously retry finding the element until either the element is found or the time expires. The length of time this method will wait is controlled through default_max_wait_time.

Parameters:

  • locator (String)

    Which field to fill in

  • options (Hash)
  • with: (String) (defaults to: )

    The value to fill in

Options Hash (**options):

  • wait (false, true, Numeric)

    Maximum time to wait for matching element to appear. Defaults to default_max_wait_time.

  • currently_with (String)

    The current value property of the field to fill in

  • multiple (Boolean)

    Match fields that can have multiple values?

  • id (String, Regexp)

    Match fields that match the id attribute

  • name (String)

    Match fields that match the name attribute

  • placeholder (String)

    Match fields that match the placeholder attribute

  • class (String, Array<String>, Regexp)

    Match fields that match the class(es) provided

  • fill_options (Hash)

    Driver specific options regarding how to fill fields (Defaults come from default_set_options)

Returns:


88
89
90
91
92
# File 'lib/capybara/node/actions.rb', line 88

def fill_in(locator = nil, with:, currently_with: nil, fill_options: {}, **find_options)
  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