Bạn cũng có thể hướng dẫn Capybara để không bỏ qua yếu tố ẩn trên toàn cầu trong bạn spec_helper.rb
hoặc tương đương. Hành vi mặc định có thể được ghi đè:
# default behavior for hidden elements
# Capybara.ignore_hidden_elements = false
# find all elements (hidden or visible)
page.all(".articles .article[id='foo']")
# find visible elements only (overwrite the standard behavior just for this query)
page.all(".articles .article[id='foo']", :visible => true)
# changing the default behavior (e.g. in your features/support/env.rb file)
Capybara.ignore_hidden_elements = true
# now the query just finds visible nodes by default
page.all(".articles .article[id='foo']")
# but you can change the default behaviour by passing the :visible option again
page.all(".articles .article[id='foo']", :visible => false)
Ví dụ lấy từ this article.
Cảm ơn, tôi đã kết thúc với 'elem = page.find_by_id' ('my_element_id') sau đây; elem.value.should eq Date.today.to_s' –
Tôi cũng đã sử dụng ['find_by_id'] (http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders:find_by_id):' assert_equal photo .updated_at.to_datetime.to_s, page.find_by_id ('hidden_field_photo_updated_at'). value.to_datetime.to_s' – user664833