Class: FireWatir::SelectList

Inherits:
Object
  • Object
show all
Includes:
Watir::SelectListCommonWatir
Defined in:
lib/watirloo/extension/firewatir_ducktape.rb

Instance Method Summary collapse

Methods included from Watir::SelectListCommonWatir

#selected_item, #selected_items, #selected_value, #selected_values

Instance Method Details

#_set(how, what) ⇒ Object

set :value or :text



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/watirloo/extension/firewatir_ducktape.rb', line 29

def _set(how, what)
  if what.kind_of? Array
    what.each { |item| _set(how,item)} # call self with individual item
  else
    if what.kind_of? Fixnum # if by position then translate to set by text
      if (0..items.size).member? what
        _set :text, items[what-1] #call self with found item
      else
        raise ::Watir::Exception::WatirException, "number #{item} is out of range of item count"
      end
    else
      select_items_in_select_list(how, what)  #finally as :value or :text
    end
  end

end

#select(item) ⇒ Object Also known as: set

accepts one text item or array of text items. if array then sets one after another. For single select lists the last item in array wins

examples

select_list.set 'bla' # => single option text
select_list.set ['bla','foo','gugu'] # => set 3 options by text. If 
    this is a single select list box it will set each value in turn
select_list set 1 # => set the first option in a list
select_list.set [1,3,5] => set the first, third and fith options


18
19
20
# File 'lib/watirloo/extension/firewatir_ducktape.rb', line 18

def select( item )
  _set(:text, item)
end

#select_value(value) ⇒ Object Also known as: set_value

set item by the option value attribute. if array then set one after anohter. see examples in set method



24
25
26
# File 'lib/watirloo/extension/firewatir_ducktape.rb', line 24

def select_value( value )
  _set(:value, value)
end

#valuesObject

returns array of value attributes each option usually has a value attribute which is hidden to the person viewing the page



51
52
53
54
55
56
57
# File 'lib/watirloo/extension/firewatir_ducktape.rb', line 51

def values
  a = []
  items.each do |item|
    a << option(:text, item).value
  end
  return a
end