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
Instance Attribute Summary
Attributes inherited from Element
Attributes included from Container
Instance Method Summary collapse
-
#clear ⇒ Object
Clear all selected options.
- #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
-
#multiple? ⇒ Boolean
Returns true if the select list supports multiple selections.
-
#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) whose text or label matches the given string.
-
#select_value(value) ⇒ String
Selects the option(s) whose value attribute matches the given string.
-
#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, #focused?, #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, #del, #dels, #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, #ins, #inses, #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
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
28 29 30 |
# File 'lib/celerity/elements/select_list.rb', line 28 def clear @object.getSelectedOptions.each { |e| e.setSelected(false) } if multiple? end |
#clearSelection ⇒ Object
58 |
# File 'lib/celerity/watir_compatibility.rb', line 58 alias_method :clearSelection, :clear |
#getAllContents ⇒ Object
57 |
# File 'lib/celerity/watir_compatibility.rb', line 57 alias_method :getAllContents, :options |
#getSelectedItems ⇒ Object
56 |
# File 'lib/celerity/watir_compatibility.rb', line 56 alias_method :getSelectedItems, :selected_options |
#include?(value) ⇒ true, false
Returns true if the select list has one or more options matching the given value.
86 87 88 89 |
# File 'lib/celerity/elements/select_list.rb', line 86 def include?(value) assert_exists !!@object.getOptions.find { |e| matches_option?(e, value) } end |
#includes? ⇒ Object
59 |
# File 'lib/celerity/watir_compatibility.rb', line 59 alias_method :includes?, :include? |
#multiple? ⇒ Boolean
Returns true if the select list supports multiple selections
121 122 123 |
# File 'lib/celerity/elements/select_list.rb', line 121 def multiple? type == "select-multiple" end |
#options ⇒ Array<String>
Returns 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 |
#select(value) ⇒ String 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.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/celerity/elements/select_list.rb', line 42 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 |
#select_value(value) ⇒ String
Selects the option(s) whose value attribute matches the given string.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/celerity/elements/select_list.rb', line 68 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 |
#selected?(value) ⇒ true, false
Returns true if any of the selected options match the given value.
99 100 101 102 103 |
# File 'lib/celerity/elements/select_list.rb', line 99 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.
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 |
#type ⇒ String
Returns ‘select-multiple’ if the select list has the ‘multiple’ attribute, defined, otherwise ‘select-one’.
112 113 114 115 |
# File 'lib/celerity/elements/select_list.rb', line 112 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.
132 133 134 135 136 137 |
# File 'lib/celerity/elements/select_list.rb', line 132 def value assert_exists if (option = @object.getSelectedOptions.to_a.first) option.getValueAttribute end end |