Class: Celerity::SelectList
- Inherits:
-
InputElement
- Object
- Element
- InputElement
- Celerity::SelectList
- Defined in:
- lib/celerity/watir_compatibility.rb,
lib/celerity/elements/select_list.rb
Constant Summary collapse
- TAGS =
[ Identifier.new('select') ]
- DEFAULT_HOW =
:name
Constants inherited from InputElement
Constants inherited from Element
Element::ATTRIBUTES, Element::BASE_ATTRIBUTES, Element::CELLHALIGN_ATTRIBUTES, Element::CELLVALIGN_ATTRIBUTES, Element::HTML_401_TRANSITIONAL, Element::TO_S_SIZE
Instance Attribute Summary
Attributes inherited from Element
Attributes included from Container
Instance Method Summary collapse
-
#clear ⇒ Object
Clear all selected options.
- #clear_selection ⇒ Object
- #clearSelection ⇒ Object
- #getAllContents ⇒ Object
- #getSelectedItems ⇒ Object
-
#include?(value) ⇒ true, false
Returns true if the select list has one or more options matching the given value.
- #includes? ⇒ Object
-
#options ⇒ Array<String>
An array of strings representing the text value of the select list’s options.
-
#select(value) ⇒ String?
(also: #set)
Select the option(s) matching the given value.
- #select_value ⇒ Object
-
#selected?(value) ⇒ true, false
Returns true if any of the selected options match the given value.
-
#selected_options ⇒ Array<String>
An array of strings representing the text value of the currently selected options.
-
#type ⇒ String
Returns ‘select-multiple’ if the select list has the ‘multiple’ attribute, defined, otherwise ‘select-one’.
-
#value ⇒ String?
Returns the value of the first selected option in the select list.
Methods inherited from InputElement
Methods included from DisabledElement
#assert_enabled, #disabled?, #enabled?
Methods included from ClickableElement
#click, #click_and_attach, #double_click, #download, #right_click
Methods inherited from Element
#assert_exists, #attribute_string, #attribute_value, #exists?, #fire_event, #focus, #initialize, #javascript_object, #locate, #method_missing, #methods, #object, #parent, #respond_to?, #text, #to_s, #to_xml, #visible?, #xpath
Methods included from Container
#area, #areas, #button, #buttons, #cell, #cells, #check_box, #checkboxes, #container=, #contains_text, #dd, #dds, #div, #divs, #dl, #dls, #dt, #dts, #em, #ems, #file_field, #file_fields, #form, #forms, #frame, #frames, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #hidden, #hiddens, #image, #images, #inspect, #label, #labels, #li, #link, #links, #lis, #map, #maps, #meta, #metas, #ol, #ols, #option, #p, #pre, #pres, #ps, #radio, #radios, #row, #rows, #select_list, #select_lists, #span, #spans, #strong, #strongs, #table, #tables, #tbodies, #tbody, #text_field, #text_fields, #tfoot, #tfoots, #th, #thead, #theads, #ths, #ul, #uls, #update_page
Methods included from ShortInspect
Constructor Details
This class inherits a constructor from Celerity::Element
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Celerity::Element
Instance Method Details
#clear ⇒ Object
Clear all selected options
30 31 32 33 34 |
# File 'lib/celerity/elements/select_list.rb', line 30 def clear # assert_exists called by SelectList#type here # TODO: should update page for each option changed? @object.getSelectedOptions.each { |e| e.setSelected(false) } unless type() == 'select-one' end |
#clear_selection ⇒ Object
70 |
# File 'lib/celerity/watir_compatibility.rb', line 70 alias_method :clear_selection, :clear |
#clearSelection ⇒ Object
69 |
# File 'lib/celerity/watir_compatibility.rb', line 69 alias_method :clearSelection, :clear |
#getAllContents ⇒ Object
68 |
# File 'lib/celerity/watir_compatibility.rb', line 68 alias_method :getAllContents, :options |
#getSelectedItems ⇒ Object
67 |
# File 'lib/celerity/watir_compatibility.rb', line 67 alias_method :getSelectedItems, :selected_options |
#include?(value) ⇒ true, false
Returns true if the select list has one or more options matching the given value.
69 70 71 72 |
# File 'lib/celerity/elements/select_list.rb', line 69 def include?(value) assert_exists !!@object.getOptions.find { |e| matches_option?(e, value) } end |
#includes? ⇒ Object
72 |
# File 'lib/celerity/watir_compatibility.rb', line 72 alias_method :includes?, :include? |
#options ⇒ Array<String>
Returns An array of strings representing the text value of the select list’s options.
10 11 12 13 14 15 |
# File 'lib/celerity/elements/select_list.rb', line 10 def assert_exists @object.getOptions.map do |e| e.asText.empty? ? e.getLabelAttribute : e.asText end end |
#select(value) ⇒ String? Also known as: set
Select the option(s) matching the given value. If several options match the value given, all will be selected.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/celerity/elements/select_list.rb', line 46 def select(value) assert_exists raise NoValueFoundException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}" unless include?(value) selected = nil matching = @object.getOptions.select do |option| next unless matches_option?(option, value) selected ||= option.asText @container.update_page option.click end selected end |
#select_value ⇒ Object
71 |
# File 'lib/celerity/watir_compatibility.rb', line 71 alias_method :select_value, :select |
#selected?(value) ⇒ true, false
Returns true if any of the selected options match the given value.
82 83 84 85 86 |
# File 'lib/celerity/elements/select_list.rb', line 82 def selected?(value) assert_exists raise UnknownObjectException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}" unless include?(value) !!@object.getOptions.find { |e| matches_option?(e, value) && e.isSelected } end |
#selected_options ⇒ Array<String>
Returns An array of strings representing the text value of the currently selected options.
21 22 23 24 |
# File 'lib/celerity/elements/select_list.rb', line 21 def assert_exists @object.getSelectedOptions.map { |e| e.asText.empty? ? e.getLabelAttribute : e.asText } end |
#type ⇒ String
Returns ‘select-multiple’ if the select list has the ‘multiple’ attribute, defined, otherwise ‘select-one’.
95 96 97 98 |
# File 'lib/celerity/elements/select_list.rb', line 95 def type assert_exists 'select-' + (@object.hasAttribute('multiple') ? 'multiple' : 'one') end |
#value ⇒ String?
Returns the value of the first selected option in the select list. Returns nil if no option is selected.
107 108 109 110 111 112 |
# File 'lib/celerity/elements/select_list.rb', line 107 def value assert_exists if (option = @object.getSelectedOptions.to_a.first) option.getValueAttribute end end |