Posted 10 months ago. Visible to the public.

Capybara: How to find a hidden field by its label

To find an input with the type hidden, you need to specify the type hidden:

Copy
find_field('Some label', type: :hidden)

Otherwise you will see an exception :

Copy
find_field('Some label') # => Capybara::ElementNotFound: Unable to find field "Some label" that is not disabled`.

Note: Usually you don't need to check the input of hidden fields in an integration test. But e.g. waiting for a datepicker library to write the expected value to this field before continuing the test, which prevents flaky tests, is a valid use case.

By refactoring problematic code and creating automated tests, makandra can vastly improve the maintainability of your Rails application.

Owner of this card:

Avatar
Emanuel De
Last edit:
10 months ago
by Niklas Hasselmeyer
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Emanuel De to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more