Reputation: 2731
I want to find elements by a "test" data attribute and fill them in like the following:
When(/^I sign in with valid credentials$/) do
email = page.find("data-test='email'")
password = page.find("data-test='password'")
fill_in email, with: @user.email
fill_in password, with: @user.password
submit = page.find("[data-test='submit']")
submit.click
end
The button works fine, but the inputs throw the following error:
Unable to find field #<Capybara::Element tag="input"> (Capybara::ElementNotFound)
Is there a way to do this in capybara? Thanks in advance for the help.
Upvotes: 2
Views: 2691
Reputation: 2691
fill_in
method accepts element's id, name or label text, so it might not work with the result the find method returns. In your case try the set
method:
find("input[data-test='email']").set(@user.email)
Upvotes: 6