Class: Celerity::SelectList
- Inherits:
-
Celerity::InputElement
- Object
- Celerity::Element
- Celerity::InputElement
- Celerity::SelectList
- Defined in:
- lib/celerity/elements/select_list.rb,
lib/celerity/watir_compatibility.rb
Overview
SelectList
Constant Summary
- TAGS =
[ Identifier.new('select') ]
- DEFAULT_HOW =
:name
Constants inherited from Celerity::InputElement
Constants inherited from Celerity::Element
ATTRIBUTES, BASE_ATTRIBUTES, CELLHALIGN_ATTRIBUTES, CELLVALIGN_ATTRIBUTES, DEFAULT_HOW, HTML_401_TRANSITIONAL, TAGS
Method Summary
- - (Object) clear (also: #clearSelection) Clear all selected options.
- - (true) include?(value) (also: #includes?) Returns true if the select list has one or more options matching the given value.
- - (Object) multiple? Returns true if the select list supports multiple selections.
- - (Array<String>) options (also: #getAllContents) An array of strings representing the text value of the select list’s options.
- - (String) select(value) (also: #set) Select the option(s) whose text or label matches the given string.
- - (String) select_value(value) Selects the option(s) whose value attribute matches the given string.
- - (true) selected?(value) Returns true if any of the selected options match the given value.
- - (Array<String>) selected_options (also: #getSelectedItems) An array of strings representing the text value of the currently selected options.
- - (String) type Returns ‘select-multiple’ if the select list has the ‘multiple’ attribute, defined, otherwise ‘select-one’.
- - (String) value Returns the value of the first selected option in the select list.
Methods inherited from Celerity::InputElement
#assert_not_readonly, #readonly?
Methods included from Celerity::ClickableElement
#assert_exists_and_enabled, #click, #click_and_attach, #double_click, #download, #right_click
Methods included from Celerity::DisabledElement
#assert_enabled, #disabled?, #enabled?
Methods inherited from Celerity::Element
#==, #assert_exists, #attribute_string, #attribute_value, #exists?, #fire_event, #focus, #identifier_string, #initialize, #javascript_object, #locate, #method_missing, #methods, #object, #parent, #respond_to?, #selector_to_attribute, #text, #to_s, #to_xml, #visible?, #xpath
Methods included from Celerity::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, #rescue_status_code_exception, #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
Methods included from Celerity::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
Method Details
- (Object) clear Also known as: clearSelection
Clear all selected options
28 29 30 31 |
# File 'lib/celerity/elements/select_list.rb', line 28 def clear # assert_exists called by SelectList#type here @object.getSelectedOptions.each { |e| e.setSelected(false) } unless type() == 'select-one' end |
- (true) include?(value) Also known as: includes?
Returns true if the select list has one or more options matching the given value.
87 88 89 90 |
# File 'lib/celerity/elements/select_list.rb', line 87 def include?(value) assert_exists !!@object.getOptions.find { |e| matches_option?(e, value) } end |
- (Object) multiple?
Returns true if the select list supports multiple selections
122 123 124 |
# File 'lib/celerity/elements/select_list.rb', line 122 def multiple? type == "select-multiple" end |
- (Array<String>) options Also known as: getAllContents
An array of strings representing the text value of the select list’s options.
10 11 12 13 |
# File 'lib/celerity/elements/select_list.rb', line 10 def assert_exists @object.getOptions.map { |e| e.asText.empty? ? e.getLabelAttribute : e.asText } end |
- (String) select(value) Also known as: set
Select the option(s) whose text or label matches the given string. If several options match the value given, all will be selected.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/celerity/elements/select_list.rb', line 43 def select(value) assert_exists selected = nil @object.getOptions.select do |option| next unless matches_option?(option, value) selected ||= option.asText option.click end unless selected raise NoValueFoundException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}" end selected end |
- (String) select_value(value)
Selects the option(s) whose value attribute matches the given string.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/celerity/elements/select_list.rb', line 69 def select_value(value) assert_exists selected = @object.getOptions.map { |e| e.click if Util.matches?(e.getValueAttribute, value) }.compact.first unless selected raise NoValueFoundException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}" end selected.asText end |
- (true) selected?(value)
Returns true if any of the selected options match the given value.
100 101 102 103 104 |
# File 'lib/celerity/elements/select_list.rb', line 100 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 |
- (Array<String>) selected_options Also known as: getSelectedItems
An array of strings representing the text value of the currently selected options.
19 20 21 22 |
# File 'lib/celerity/elements/select_list.rb', line 19 def assert_exists @object.getSelectedOptions.map { |e| e.asText.empty? ? e.getLabelAttribute : e.asText } end |
- (String) type
Returns ‘select-multiple’ if the select list has the ‘multiple’ attribute, defined, otherwise ‘select-one’.
113 114 115 116 |
# File 'lib/celerity/elements/select_list.rb', line 113 def type assert_exists 'select-' + (@object.hasAttribute('multiple') ? 'multiple' : 'one') end |
- (String) value
Returns the value of the first selected option in the select list. Returns nil if no option is selected.
133 134 135 136 137 138 |
# File 'lib/celerity/elements/select_list.rb', line 133 def value assert_exists if (option = @object.getSelectedOptions.to_a.first) option.getValueAttribute end end |