【问题标题】:Ruby Mechanize: verifying a "select" element valueRuby Mechanize:验证“选择”元素值
【发布时间】:2013-01-06 05:30:32
【问题描述】:

我正在尝试使用 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

...对应第三个选项:“Testing”

还有选择 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>

我正在尝试对从选择框中选择的项目进行某种验证。

【问题讨论】:

  • 也许我因为感冒而变得密集,但我认为“之前”和“之后”示例之间绝对没有区别,vimdiff 也没有。想为我们解决这个问题?

标签: ruby nokogiri mechanize-ruby


【解决方案1】:

只需检查:

@form.field_with(:name => "time_entry[activity_id]").value

或者更简单:

@form.values

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2017-01-03
    • 1970-01-01
    • 1970-01-01
    • 2014-10-20
    • 1970-01-01
    • 2016-02-03
    相关资源
    最近更新 更多