我已经发现,当我想为文本字段、文本区域或密码字段设置值时,我可以使用 id、name 或 label,如something
. fill_in something, :with => some_value
但是,当我尝试为<input type="hidden">
字段设置值时,这种方法会失败(我想这样做,因为这些通常是我单独测试的填充客户端脚本)。我怎么能用水豚设置这样一个隐藏的领域?可能吗?
HTML:
<input id='offer_latitude' name='offer[latitude]' type='hidden'>
<input id='offer_longitude' name='offer[longitude]' type='hidden'>
规格:
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
给出:
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