我试图使用ruby的机械化验证下拉值
我有这张漂亮的印刷品:
在:
#<Mechanize::Form
...
[selectlist:0xefdae4 type: name: time_entry[activity_id] value: []]}
...
{buttons [submit:0xefe124 type: submit name: commit value: Save]}>
后:
#<Mechanize::Form
...
[selectlist:0xefdae4 type: name: time_entry[activity_id] value: []]}
...
{buttons [submit:0xefe124 type: submit name: commit value: Save]}>
我正在运行的代码:
@form.field_with(:name => "time_entry[activity_id]").options[2].select
...对应第3个选项:&#34;测试&#34;
选择HTML元素:
<select id="time_entry_activity_id" name="time_entry[activity_id]">
<option value="">--- Please select ---</option>
<option value="8">Design</option>
<option value="9">Development</option>
<option value="13">Testing</option>
<option value="14">Dingo</option>
<option value="15">ABPs</option>
</select>
我试图从选择框中选择哪个项目进行某种验证。
答案 0 :(得分:1)
请检查:
@form.field_with(:name => "time_entry[activity_id]").value
或者更容易:
@form.values