Class: Watir::Option

Inherits:
Object
  • Object
show all
Includes:
Exception, OptionAccess
Defined in:
lib/watir/input_elements.rb

Overview

An item in a select list. Normally a user would not need to create this object as it is returned by the Watir::SelectList#option method

Instance Method Summary collapse

Methods included from OptionAccess

#selected, #text, #value

Constructor Details

#initialize(select_list, attribute, value) ⇒ Option

Returns a new instance of Option.



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/watir/input_elements.rb', line 184

def initialize(select_list, attribute, value)
  @select_list = select_list
  @how = attribute
  @what = value
  @option = nil
  
  unless [:text, :value, :label].include? attribute
    raise MissingWayOfFindingObjectException,
                "Option does not support attribute #{@how}"
  end
  @select_list.o.each do |option| # items in the list
    if value.matches(option.invoke(attribute.to_s))
      @option = option
      break
    end
  end
  
end

Instance Method Details

#selectObject

select the accessed option in select_list



211
212
213
214
# File 'lib/watir/input_elements.rb', line 211

def select
  assert_exists
  @select_list.select_item_in_select_list(@how, @what)
end