Categories
ruby on rails

Fetching value of hidden input field in capybara

There can be many instances in testing with capybara where you might need to interact with hidden fields. By default capybara’s

find_field

selector ignores hidden fields.
To get the value of the hidden field you can use

page.all
page.all("input['name=you_input_name']", :visible => false).first.value
# you have to use first as it returns and array of element matching the query criteria

To set the value of the hidden field you can use

page.all("input['name=you_input_name']", :visible => false).first.set(value_to_set)