Capybara can find but not fill_in

you can do find("#user_email").set "[email protected]". See answer https://stackoverflow.com/a/8544650/3163914


if it is an autocomplete field, you can use this:

  def fill_in_autocomplete(id, value)
    page.execute_script("document.getElementById('#{id}').setAttribute('value', '#{value}');")
  end


The locator for find and fill_in are different:

  • find - When the first parameter is not a symbol, it is assumed to be the Capybara.default_selector - ie a css-selector or xpath.
  • fill_in - The first parameter is the field's name, id or label text.

The string "#user_email" represents a css-selector. This is why it works in find but not fill_in.

For fill_in to work, you need to just pass in the id value - ie just "user_email".

within("#login_form"){ fill_in("user_email", with: "[email protected]")}  

Tags:

Capybara