(Some background if it helps: our Rails app has a bunch of potentially repetitive dynamically-generated forms using double-nested fIElds,with IDs in the pattern foo_attributes_0_bar_attributes_0_bat_12,where basically the first two numbers increment based on how many repetitions of the nested form there are,and the last number is the ID of the particular “bat” object. This makes selection in Cucumber for testing difficult!)
我想写一些像这样的步骤:
When I check the 1st checkBox with the value "Bat 12"
要么
When I check the 3rd checkBox with ID matching "bar_attributes_bat"
我有以下工作,但我找到复选框(或字段)的方法对我来说似乎非常糟糕和低效:
When /^I check the (\d+)(st|nd|rd|th) checkBox with the value "([^"]*)"$/ do |number,junk,value| check(page.all("input").select {|el| el.node['value'] == value}[(number.to_i-1)].node['ID'])endWhen /^I check the (\d+)(st|nd|rd|th) checkBox with ID matching "([^"]*)"$/ do |number,ID_string| check(page.all("input").select {|el| el.node['ID'] && el.node['ID'].match(/#{ID_string}/)}[(number.to_i-1)].node['ID'])end
有没有更好的方法来选择这些输入元素?
解决方法When /^I check the (\d+)(st|nd|rd|th) checkBox with the value "([^"]*)"$/ do |index,value| page.all("input[value='#{value}']")[index.to_i-1].checkend总结
以上是内存溢出为你收集整理的复选框 – 当多个相似字段出现在表单中时,更好的黄瓜(基于水豚)选择全部内容,希望文章能够帮你解决复选框 – 当多个相似字段出现在表单中时,更好的黄瓜(基于水豚)选择所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)