Class: Watir::SelectList

Inherits:
Object show all
Includes:
SelectListCommonWatir
Defined in:
lib/watirloo/extension/watir_ducktape.rb

Overview

SelectList acts like RadioGroup or CheckboxGroup They all have options to select There are two kinds of SelectLists. SingleSelect and MultiSelect SelectList presents user with visible items to select from. Each Item has a visible :text and invisible :value attributes (sometimes :value attributes are missing)

In Watirloo The invisible :value attributes of options we call :values The visible :text of options we call :items The selected items as visible text we call :selected The selected items as values we call :selected_values

example of single select list

<select name="controlname">
  <option value="opt0"></option>
  <option value="opt1">item1</option>
  <option value="opt2" selected>item2</option>
</select> 

items => ['', 'item1', 'item2']
values => ['opt0','opt1', 'opt2']
selected => ['item2']
selected_values => ['opt2']

example of multi select list

<select name="controlname" multiple size=2>
  <option value="o1">item1
  <option value="o2" selected>item2
  <option value="o3" selected>item3
</select>

items => ['item1', 'item2', 'item3']
values => ['o1','o2','o3']
selected => ['item2', 'item3']
selected_values => ['o2', 'o3']

Instance Method Summary collapse

Methods included from SelectListCommonWatir

#selected_item, #selected_items, #selected_value, #selected_values

Instance Method Details

#reflectObject



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/watirloo/extension/watir_ducktape.rb', line 532

def reflect
  ret = []
  self.each do |item|
    name = item.name
    facename = suggest_def_name name
    values = item.values
    items = item.items
    selected_item = item.selected_item
    selected_value = item.selected_value

    ret << "face(:#{facename}) {doc.select_list(:name, #{name.inspect})}"
    ret << "#{facename}.items.should == #{items.inspect}"
    ret << "#{facename}.values.should == #{values.inspect}"
    ret << "#{facename}.selected_item.should == #{selected_item.inspect}"
    ret << "#{facename}.selected_value.should == #{selected_value.inspect}"
  end
  ret
end

#set(item) ⇒ Object

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


504
505
506
# File 'lib/watirloo/extension/watir_ducktape.rb', line 504

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

#set_value(value) ⇒ Object

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



510
511
512
# File 'lib/watirloo/extension/watir_ducktape.rb', line 510

def set_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



517
518
519
520
521
522
523
# File 'lib/watirloo/extension/watir_ducktape.rb', line 517

def values
  a = []
  attribute_value('options').each do |item|
    a << item.value
  end
  return a
end