Search code examples
ruby-on-railsruby-on-rails-5ruby-on-rails-6

Rails 5/6 System test not finding input field


My Rails 6 system test with Capybara is not finding a text_field input in my haml code:

  .form-group
    = f.label :summary
    = f.text_field :summary, placeholder: 'A brief 2-3 lines summarizing your idea', class: 'form-control summary'

With a test:

fill_in "Summary", with: "Some generic text" 

I get the following error:

Error:
ActivitiesTest#test_creating_an_activity:
  Capybara::ElementNotFound: Unable to find field "Summary" that is not disabled
  test/system/activities_test.rb:20:in `block in <class:ActivitiesTest>'

Solution

  • Turns out, that if you use a placeholder, then you have to do the fill_in on that text:

    fill_in "A brief 2-3 lines summarizing your idea", with: "Some generic text"
    

    and it will work.