【发布时间】:2012-04-10 04:18:33
【问题描述】:
我正在尝试使用 Mechanize 和 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 是: 相关的 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").value = "Foo"应该适用于我的理解。唯一要检查的是查看实际网页。 -
我也无法在 HTML 中选择任何
标签: ruby mechanize mechanize-ruby