复选框 – 当多个相似字段出现在表单中时,更好的黄瓜(基于水豚)选择

复选框 – 当多个相似字段出现在表单中时,更好的黄瓜(基于水豚)选择,第1张

概述(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_

(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
总结

以上是内存溢出为你收集整理的复选框 – 当多个相似字段出现在表单中时,更好的黄瓜(基于水豚)选择全部内容,希望文章能够帮你解决复选框 – 当多个相似字段出现在表单中时,更好的黄瓜(基于水豚)选择所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1083777.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存