Class: Watir::SelectList
- Inherits:
-
InputElement
- Object
- Element
- InputElement
- Watir::SelectList
- Defined in:
- lib/watir-classic/input_elements.rb
Overview
This class is the way in which select boxes are manipulated. Normally a user would not need to create this object as it is returned by the Watir::Container#select_list method
Constant Summary
Constants inherited from Element
Instance Attribute Summary
Attributes inherited from Element
Attributes included from Container
#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed
Instance Method Summary collapse
-
#clear ⇒ Object
This method clears the selected items in the select box.
-
#include?(text_or_regexp) ⇒ Boolean
Does the SelectList include the specified option (text)?.
-
#select(item) ⇒ Object
This method selects an item, or items in a select box, by text.
-
#select_value(item) ⇒ Object
Selects an item, or items in a select box, by value.
-
#selected?(text_or_regexp) ⇒ Boolean
Is the specified option (text) selected? Raises exception of option does not exist.
-
#selected_options ⇒ Object
Returns array of the selected text items in a select box Raises UnknownObjectException if the select box is not found.
Methods inherited from InputElement
Methods inherited from Element
#<=>, #__ole_inner_elements, #activeObjectHighLightColor, #assert_enabled, #assert_exists, #attribute_value, #click, #click!, #create_event, #disabled?, #dispatch_event, #document, #double_click, #enabled?, #exists?, #fire_event, #flash, #focus, #focused?, #initialize, #inspect, #locate, #method_missing, #ole_object, #ole_object=, #parent, #right_click, #send_keys, #style, #tag_name, #text, #to_s, #to_subtype, #type_keys, #typingspeed, #visible?
Methods included from DragAndDropHelper
#drag_and_drop_by, #drag_and_drop_on
Methods included from Container
#__ole_inner_elements, #alert, #locator_for, #modal_dialog, #set_container, support_element, #wait
Methods included from Exception
Methods included from ElementExtensions
#present?, #wait_until_present, #wait_while_present, #when_present
Constructor Details
This class inherits a constructor from Watir::Element
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Watir::Element
Instance Method Details
#clear ⇒ Object
This method clears the selected items in the select box
26 27 28 29 30 |
# File 'lib/watir-classic/input_elements.rb', line 26 def clear perform_action do .each(&:clear) end end |
#include?(text_or_regexp) ⇒ Boolean
Does the SelectList include the specified option (text)?
64 65 66 |
# File 'lib/watir-classic/input_elements.rb', line 64 def include? text_or_regexp !.map(&:text).grep(text_or_regexp).empty? end |
#select(item) ⇒ Object
This method selects an item, or items in a select box, by text. Raises NoValueFoundException if the specified value is not found.
* item - the thing to select, string or reg exp
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/watir-classic/input_elements.rb', line 35 def select(item) = [] perform_action do = matching_items_in_select_list(:text, item) + matching_items_in_select_list(:label, item) + matching_items_in_select_list(:value, item) raise NoValueFoundException, "No option with :text, :label or :value of #{item.inspect} in this select element" if .empty? .each(&:select) end .first.text end |
#select_value(item) ⇒ Object
Selects an item, or items in a select box, by value. Raises NoValueFoundException if the specified value is not found.
* item - the value of the thing to select, string or reg exp
50 51 52 53 54 55 |
# File 'lib/watir-classic/input_elements.rb', line 50 def select_value(item) = matching_items_in_select_list(:value, item) raise NoValueFoundException, "No option with :value of #{item.inspect} in this select element" if .empty? .each(&:select) .first.value end |
#selected?(text_or_regexp) ⇒ Boolean
Is the specified option (text) selected? Raises exception of option does not exist.
69 70 71 72 |
# File 'lib/watir-classic/input_elements.rb', line 69 def selected? text_or_regexp raise UnknownObjectException, "Option #{text_or_regexp.inspect} not found." unless include? text_or_regexp !.map(&:text).grep(text_or_regexp).empty? end |
#selected_options ⇒ Object
Returns array of the selected text items in a select box Raises UnknownObjectException if the select box is not found.
59 60 61 |
# File 'lib/watir-classic/input_elements.rb', line 59 def .select(&:selected?) end |