Class: Watir::RadioSet
- Inherits:
-
Object
- Object
- Watir::RadioSet
- Extended by:
- Forwardable
- Includes:
- Enumerable, Exception
- Defined in:
- lib/watir/radio_set.rb
Instance Attribute Summary collapse
-
#frame ⇒ Object
readonly
Returns the value of attribute frame.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Returns true if two elements are equal.
-
#[](idx) ⇒ Object
Get the n’th radio button in this set.
-
#disabled? ⇒ Boolean
Returns true if all radio buttons in the set are disabled.
-
#each {|element| ... } ⇒ Object
Yields each Radio associated with this set.
-
#enabled? ⇒ Boolean
Returns true if any radio buttons in the set are enabled.
-
#include?(str_or_rx) ⇒ Boolean
Returns true if the radio set has one or more radio buttons where label matches the given value.
-
#initialize(query_scope, selector) ⇒ RadioSet
constructor
A new instance of RadioSet.
-
#name ⇒ String
Returns the name attribute for the set.
-
#radio(opt = {}) ⇒ Object
Watir::Radio.
-
#radios(opt = {}) ⇒ Object
Watir::RadioCollection.
-
#select(str_or_rx) ⇒ String
(also: #set)
Select the radio button whose value or label matches the given string.
-
#selected ⇒ Watir::Radio?
Returns the selected Radio element.
-
#selected?(str_or_rx) ⇒ Boolean
Returns true if any of the radio button label matches the given value.
-
#text ⇒ String?
Returns the text of the selected radio button in the set.
-
#type ⇒ String
If RadioSet exists, this always returns ‘radio’.
-
#value ⇒ String?
Returns the value of the selected radio button in the set.
Constructor Details
#initialize(query_scope, selector) ⇒ RadioSet
Returns a new instance of RadioSet.
13 14 15 16 17 18 |
# File 'lib/watir/radio_set.rb', line 13 def initialize(query_scope, selector) raise ArgumentError, "invalid argument: #{selector.inspect}" unless selector.is_a? Hash @source = Radio.new(query_scope, selector) @frame = @source.parent(tag_name: 'form') end |
Instance Attribute Details
#frame ⇒ Object (readonly)
Returns the value of attribute frame.
11 12 13 |
# File 'lib/watir/radio_set.rb', line 11 def frame @frame end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
11 12 13 |
# File 'lib/watir/radio_set.rb', line 11 def source @source end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Returns true if two elements are equal.
202 203 204 |
# File 'lib/watir/radio_set.rb', line 202 def ==(other) other.is_a?(self.class) && radios == other.radios end |
#[](idx) ⇒ Object
Get the n’th radio button in this set
42 43 44 |
# File 'lib/watir/radio_set.rb', line 42 def [](idx) radios[idx] end |
#disabled? ⇒ Boolean
Returns true if all radio buttons in the set are disabled.
90 91 92 |
# File 'lib/watir/radio_set.rb', line 90 def disabled? !enabled? end |
#each {|element| ... } ⇒ Object
Yields each Radio associated with this set.
32 33 34 |
# File 'lib/watir/radio_set.rb', line 32 def each(&block) radios.each(&block) end |
#enabled? ⇒ Boolean
Returns true if any radio buttons in the set are enabled.
80 81 82 |
# File 'lib/watir/radio_set.rb', line 80 def enabled? any?(&:enabled?) end |
#include?(str_or_rx) ⇒ Boolean
Returns true if the radio set has one or more radio buttons where label matches the given value.
122 123 124 |
# File 'lib/watir/radio_set.rb', line 122 def include?(str_or_rx) radio(label: str_or_rx).exist? end |
#name ⇒ String
Returns the name attribute for the set.
100 101 102 |
# File 'lib/watir/radio_set.rb', line 100 def name @name ||= source.name end |
#radio(opt = {}) ⇒ Object
Returns Watir::Radio.
50 51 52 53 54 55 56 57 58 |
# File 'lib/watir/radio_set.rb', line 50 def radio(opt = {}) if !name.empty? && (!opt[:name] || opt[:name] == name) frame.radio(opt.merge(name: name)) elsif name.empty? source else raise UnknownObjectException, "#{opt[:name]} does not match name of RadioSet: #{name}" end end |
#radios(opt = {}) ⇒ Object
Returns Watir::RadioCollection.
64 65 66 67 68 69 70 71 72 |
# File 'lib/watir/radio_set.rb', line 64 def radios(opt = {}) if !name.empty? && (!opt[:name] || opt[:name] == name) element_call(:wait_for_present) { frame.radios(opt.merge(name: name)) } elsif name.empty? single_radio_collection else raise UnknownObjectException, "#{opt[:name]} does not match name of RadioSet: #{name}" end end |
#select(str_or_rx) ⇒ String Also known as: set
Select the radio button whose value or label matches the given string.
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/watir/radio_set.rb', line 134 def select(str_or_rx) %i[value label].each do |key| radio = radio(key => str_or_rx) next unless radio.exist? radio.click unless radio.selected? return key == :value ? radio.value : radio.text end raise UnknownObjectException, "Unable to locate radio matching #{str_or_rx.inspect}" end |
#selected ⇒ Watir::Radio?
Returns the selected Radio element. Returns nil if no radio button is selected.
190 191 192 |
# File 'lib/watir/radio_set.rb', line 190 def selected find(&:selected?) end |
#selected?(str_or_rx) ⇒ Boolean
Returns true if any of the radio button label matches the given value.
154 155 156 157 158 159 |
# File 'lib/watir/radio_set.rb', line 154 def selected?(str_or_rx) found = frame.radio(label: str_or_rx) return found.selected? if found.exist? raise UnknownObjectException, "Unable to locate radio matching #{str_or_rx.inspect}" end |
#text ⇒ String?
Returns the text of the selected radio button in the set. Returns nil if no option is selected.
179 180 181 |
# File 'lib/watir/radio_set.rb', line 179 def text selected&.text end |
#type ⇒ String
If RadioSet exists, this always returns ‘radio’.
110 111 112 113 |
# File 'lib/watir/radio_set.rb', line 110 def type assert_exists 'radio' end |
#value ⇒ String?
Returns the value of the selected radio button in the set. Returns nil if no radio is selected.
168 169 170 |
# File 'lib/watir/radio_set.rb', line 168 def value selected&.value end |