我已经发现,当我想将值设置为文本字段,文本区域或密码字段时,我可以使用ID,名称或标签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
通常一个人不能在一个隐藏字段填写,所以为此豚没有填写他们看到https://groups.google.com/forum/? fromgroups#!topic/ruby-capybara/EstLVItkyrA进行更多讨论。但通常你要么填充它在服务器上或使用JavaScript .. – Doon
@ Doon的评论是非常真实的。如果你想检查/改变隐藏的输入,很可能你使用了错误的工具。 Capybara旨在在各种情况下测试整个应用程序,而不是测试您的JS组件。结帐[茉莉](http://pivotal.github.com/jasmine/)或[Chai](http://chaijs.com/)。然而,在某些情况下,这是明智的,例如填充在不兼容浏览器中填充的HTML5输入。 Polyfills经常隐藏正确的输入并插入额外的标记。 – skalee