2013-01-02 20 views
20

मेरे पास एक छिपे हुए फ़ील्ड वाला एक फॉर्म है जिसमें वर्तमान दिनांक है।छिपे हुए क्षेत्र के कैपिबरा परीक्षण मूल्य

मैं यह पता लगाने की कैसे करने के लिए एक capybara खोजक लिखने के लिए कोशिश कर रहा हूँ:

  1. चेक क्षेत्र वहाँ
  2. क्षेत्र

का मूल्य की जाँच है कि के साथ इस संभव है Capybara?

उत्तर

2

अपनी सरल आप find_by_css का उपयोग करके या xpath का उपयोग करके यह कर सकते हैं का पालन करें

page.find_by_css('#foo .bar a') #foo is the id the foo has .bar class 
page.find('/table/tbody/tr[3]') #path of the element we want to find 
+6

धन्यवाद, मैं निम्नलिखित 'elem = page.find_by_id (' my_element_id ') के साथ समाप्त हुआ; elem.value.should eq Date.today.to_s' –

+1

मैंने ['find_by_id'] (http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders:find_by_id) का भी उपयोग किया:' assert_equal फोटो .updated_at.to_datetime.to_s, page.find_by_id ('hidden_field_photo_updated_at')। value.to_datetime.to_s' – user664833

41

के रूप में सिर्फ इस कार्य करें:

find("#id_of_hidden_input", :visible => false).value 
+6

'दृश्यमान: झूठा' यहां मुख्य भाग है। धन्यवाद! – LouieGeetoo

+0

यह तत्व ढूंढने के लिए है, यह पोस्ट इसके खिलाफ परीक्षण करने के बारे में बात करता है: http://stackoverflow.com/questions/15066884/how-to-get-the-hidden-element-value-in-capybara – Dean

4

तुम भी Capybara हिदायत सकता है में विश्व स्तर पर छिपा तत्वों को नजरअंदाज नहीं करने के लिए अपने spec_helper.rb या समकक्ष। डिफ़ॉल्ट व्यवहार अधिरोहित जा सकता है:

# 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) 

उदाहरण this article से लिया।

संबंधित मुद्दे