Capybara find_field to find a disabled field

By default find_field in capy­bara only finds an enabled field. To find a dis­abled field, you can pass in a sec­ond argu­ment as an options hash.

For exam­ple, to find a field that is dis­abled, hav­ing a label of “Promo Code”, you can do the following

find_field('Promo Code', {disabled: true})

As per the docs, you can pass in the fol­low­ing val­ues for disabled

  • true — only finds a dis­abled field
  • false — only finds an enabled field
  • :all — finds either an enabled or dis­abled field

Ryan Sukale

Ryan is a UX engineer living in San Francisco, California.

You may also like...