Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 机械化:搜索所有表单_Ruby_Mechanize - Fatal编程技术网

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”)