Class: Selenium::WebDriver::Elements::Select
- Defined in:
- lib/selenium/webdriver/elements/select.rb
Instance Method Summary collapse
-
#initialize(element, browser) ⇒ Select
constructor
A new instance of Select.
- #select_by_text(selection) ⇒ Object
- #select_by_value(selection) ⇒ Object
Methods inherited from Element
#create_element, #element_present?, #find_element, #find_elements, #method_missing
Constructor Details
#initialize(element, browser) ⇒ Select
Returns a new instance of Select.
9 10 11 12 13 14 |
# File 'lib/selenium/webdriver/elements/select.rb', line 9 def initialize element, browser super element, browser unless element.tag_name == 'select' raise TypeError.new "Can't create Select decorator for #{element.inspect}" end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Selenium::WebDriver::Elements::Element
Instance Method Details
#select_by_text(selection) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/selenium/webdriver/elements/select.rb', line 40 def select_by_text selection if selection.is_a?(Array) unless @element['multiple'] raise "Attempt to select multiple values in a listbox with single selection mode" end = @element.find_elements :tag_name => 'option' .each do |opt| if (selection.include? opt.text) opt.select unless opt.selected? else opt.toggle if opt.selected? end end else = @element.find_elements :tag_name => 'option' .each do |opt| if (opt.text == selection) opt.select break end end end end |
#select_by_value(selection) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/selenium/webdriver/elements/select.rb', line 16 def select_by_value selection if selection.is_a?(Array) unless @element['multiple'] raise "Attempt to select multiple values in a listbox with single selection mode" end = @element.find_elements :tag_name => 'option' .each do |opt| if (selection.include? opt.value) opt.select unless opt.selected? else opt.toggle if opt.selected? end end else = @element.find_elements :tag_name => 'option' .each do |opt| if (opt.value == selection) opt.select break end end end end |