【发布时间】:2016-06-16 12:23:36
【问题描述】:
我正在寻找一种方法来检查选择的收音机并将该选项的值保存到变量中。 一旦我有了变量,我想构建一个 switch 语句,它会给我决定做什么的逻辑。
这里是 HTML:
<input type="radio" value="option_1" name="registration[registrationType]" id="option_1_id" class="radio">
(Option 1)
<input type="radio" value="option_2" name="registration[registrationType]" id="option_2_id" class="radio">
(Option 2)
<input type="radio" value="option_3" name="registration[registrationType]" id="option_3_id" class="radio" checked="checked">
(Option 3)
选项 3 是选中的选项 (checked="checked") 我想提取选项 3 (option_3) 的值并将其保存在变量中
default_option = #提取默认选项的代码
case default_option
when "option_1"
puts 'lets do something with this'
when "option_2"
puts 'lets do something with this'
when "option_3"
puts 'lets do something with this'
else
puts 'cant do much with this'
end
提前致谢!
【问题讨论】:
-
`find(:radio_button, 'option_3_id', checked: true).value' 返回什么?
-
这将返回正是我想要的 ID。谢谢
-
我会添加一个更完整的答案安迪
-
如果有帮助,请接受它;)并欢迎使用stackoverflow!
标签: ruby rspec automation automated-tests capybara