Ruby 机械化:搜索所有表单
这两个选项似乎都允许我访问文档中的第一个表单元素:Ruby 机械化:搜索所有表单,ruby,mechanize,Ruby,Mechanize,这两个选项似乎都允许我访问文档中的第一个表单元素: page.form page.forms.first 如何搜索特定的复选框,如 page.form.checkbox_with(:name=>"yep") 如果我不知道它在哪个表单中?您希望所有表单都带有该复选框,还是只包含第一个复选框 对于第一个,请执行以下操作: form = page.forms.detect { |f| f.checkbox_with(:name => "yep" ) } 对所有人来说,都是这样 for
page.form
page.forms.first
如何搜索特定的复选框,如
page.form.checkbox_with(:name=>"yep")
如果我不知道它在哪个表单中?您希望所有表单都带有该复选框,还是只包含第一个复选框 对于第一个,请执行以下操作:
form = page.forms.detect { |f| f.checkbox_with(:name => "yep" ) }
对所有人来说,都是这样
forms = page.forms.select { |f| f.checkbox_with(:name => "yep" ) }
您需要查找所有表单中的所有复选框,还是所有表单中都有复选框?如果第一次使用类似于
page.forms.collect{| form | form.checkbox_with(:name=>“yesp”)}.compact
如果第二次使用类似于page.forms.select{| form | form.checkbox_with(:name=>“yesp”)
。