I am having some very strange behaviour with Capybara. It stubbornly refuses to fill in the fields of my login form.
The locator for find
and fill_in
are different:
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: "foo@example.com")}
you can do find("#user_email").set "foo@example.com"
. 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