在Ruby中使用Mechanize选择List
发布时间:2020-12-17 03:46:09 所属栏目:百科 来源:网络整理
导读:我正在尝试使用Mechanize with Ruby设置选择列表的值.我可以使用选择列表导航到页面,使用.form方法获取表单,然后找到选择列表. report_form =page.form('form1')pp report_form.field_with(:name = "report_type") 正确返回正确的对象. 但是,我仍然无法设置
我正在尝试使用Mechanize with
Ruby设置选择列表的值.我可以使用选择列表导航到页面,使用.form方法获取表单,然后找到选择列表.
report_form =page.form('form1') pp report_form.field_with(:name => "report_type") 正确返回正确的对象. 但是,我仍然无法设置此字段的值!我试过了: report_form.field_with(:name => "report_type").options.first.select report_form.field_with(:name => "report_type").options[1].select report_form.field_with(:name => "report_type").value = "Foo" 但是当我这样做时: pp report_form.field_with(:name => "report_type") 值字段仍为空. 有什么我想念的吗?提示?窍门?更好的机械化文档比生活在http://mechanize.rubyforge.org的文档? 谢谢! 编辑:相关的HTML是: <TD> <select id="report_type" name="report_type"> <option value="Foo1">Opt 1</option> <option value="Foo2">Opt 2</option> <option value="Foo3">Opt 3</option> </select></TD> 解决方法
试试这个
report_form.field_with(:name => "report_type").option_with(:value => "Foo").click # now report_form.field_With(:name => "report_type").value should bee "Foo" (通过1,2) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |