Module: WatirRobot::Select
- Included in:
- KeywordLibrary
- Defined in:
- lib/watir_robot/keywords/select.rb
Overview
Functionality related to select list form elements
Instance Method Summary collapse
-
#clear_items_from_list(loc) ⇒ Object
Clear all select options from a drop-down select list.
-
#item_should_be_selected(list_loc, item_loc) ⇒ Object
Ensure that an item is selected.
-
#item_should_not_be_selected(list_loc, item_loc) ⇒ Object
Ensure that an item is not selected.
-
#select_all_items_from_list(loc) ⇒ Object
Select all items from a drop-down select list.
-
#select_item_from_list(list_loc, item_loc) ⇒ Object
Select a single item from a drop-down select list.
Instance Method Details
#clear_items_from_list(loc) ⇒ Object
Note:
The underlying Watir-WebDriver code will raise an error if the
Clear all select options from a drop-down select list
select list is not a multiple select list
51 52 53 |
# File 'lib/watir_robot/keywords/select.rb', line 51 def clear_items_from_list(loc) @browser.select(parse_location(loc)).clear end |
#item_should_be_selected(list_loc, item_loc) ⇒ Object
Ensure that an item is selected
64 65 66 67 |
# File 'lib/watir_robot/keywords/select.rb', line 64 def item_should_be_selected(list_loc, item_loc) raise(Exception::SelectListSelectionError, "The item described by #{item_loc} in the select list described by #{list_loc} is not selected.") unless @browser.select(parse_location(list_loc)).option(parse_location(item_loc)).selected? end |
#item_should_not_be_selected(list_loc, item_loc) ⇒ Object
Ensure that an item is not selected
75 76 77 78 |
# File 'lib/watir_robot/keywords/select.rb', line 75 def item_should_not_be_selected(list_loc, item_loc) raise(Exception::SelectListSelectionError, "The item described by #{item_loc} in the select list described by #{list_loc} is selected erroneously.") if @browser.select(parse_location(list_loc)).option(parse_location(item_loc)).selected? end |
#select_all_items_from_list(loc) ⇒ Object
Select all items from a drop-down select list
36 37 38 39 40 41 |
# File 'lib/watir_robot/keywords/select.rb', line 36 def select_all_items_from_list(loc) select_list = @browser.select(parse_location(loc)) select_list..each do |item| select_list.select_value(item.value) # Using value because it's more likely to be programmatically ensured unique end end |
#select_item_from_list(list_loc, item_loc) ⇒ Object
Select a single item from a drop-down select list
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/watir_robot/keywords/select.rb', line 17 def select_item_from_list(list_loc, item_loc) # Give user option to select by value rather than by text of option or label # Since the text is immediately visible, I assume people will default to that if item_loc[0..4].downcase == 'text=' item_loc = item_loc[5..item_loc.length] @browser.select(parse_location(list_loc)).select(item_loc) elsif item_loc[0..5].downcase == 'value=' item_loc = item_loc[6..item_loc.length] @browser.select(parse_location(list_loc)).select_value(item_loc) else raise(ArgumentError, "The only attributes allowed are 'text' and 'value'") end end |