I've already found that when I want to set value to text field, text area or password field, I can use id, name or label as something
in fill_in something, :with => some_value
. However such approach fails when I try to set value to <input type="hidden">
field (and I want to do it because those are normally filled client-side scripts which I test separately). How could I set such a hidden field with Capybara? Is it possible?
HTML:
<input id='offer_latitude' name='offer[latitude]' type='hidden'>
<input id='offer_longitude' name='offer[longitude]' type='hidden'>
spec:
describe "posting new offer" do
it "should add new offer" do
visit '/offer/new'
fill_in 'offer[latitude]', :with => '11.11'
fill_in 'offer[longitude]', :with => '12.12'
click_on 'add'
end
end
gives:
1) posting new offer should add new offer
Failure/Error: fill_in 'offer[latitude]', :with => '11.11'
Capybara::ElementNotFound:
cannot fill in, no text field, text area or password field with id, name, or label 'offer[latitude]' found
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…