Module: SeleniumPlus::Elements::Select
- Included in:
- Selenium::WebDriver::Element
- Defined in:
- lib/selenium_plus/selenium/select.rb
Instance Method Summary collapse
-
#first_selected_option ⇒ Object
Get the first selected option in this select element.
- #multiple? ⇒ Boolean
-
#select(value) ⇒ Object
Select an option by it’s text or value.
-
#select_options ⇒ Array<String>
Get all options text for this select element.
-
#select_raw ⇒ Array<Selenium::WebDriver::Element>
Get all options for this select element.
-
#select_values ⇒ Array<String>
Get all option’s values for this select element.
-
#selected_options ⇒ Array<String>
Get all selected options text for this select element.
Instance Method Details
#first_selected_option ⇒ Object
Get the first selected option in this select element
51 52 53 54 |
# File 'lib/selenium_plus/selenium/select.rb', line 51 def first_selected_option option = select_raw.find { |e| e.selected? } option.text or raise 'no options are selected' end |
#multiple? ⇒ Boolean
13 14 15 |
# File 'lib/selenium_plus/selenium/select.rb', line 13 def multiple? self[:multiple] end |
#select(value) ⇒ Object
Select an option by it’s text or value
21 22 23 24 25 |
# File 'lib/selenium_plus/selenium/select.rb', line 21 def select(value) opt = select_raw.select{ |opt| opt[:value] == value || opt.text == value } opt.first.send_keys(:control) if multiple? opt.first.click unless opt.empty? end |
#select_options ⇒ Array<String>
Get all options text for this select element
30 31 32 |
# File 'lib/selenium_plus/selenium/select.rb', line 30 def select_raw.map{ |opt| opt.text} end |
#select_raw ⇒ Array<Selenium::WebDriver::Element>
Get all options for this select element
7 8 9 10 11 |
# File 'lib/selenium_plus/selenium/select.rb', line 7 def select_raw if self.tag_name == 'select' self.find_all(:css, 'option') end end |
#select_values ⇒ Array<String>
Get all option’s values for this select element
37 38 39 |
# File 'lib/selenium_plus/selenium/select.rb', line 37 def select_values select_raw.map{ |opt| opt[:value]} end |
#selected_options ⇒ Array<String>
Get all selected options text for this select element
45 46 47 |
# File 'lib/selenium_plus/selenium/select.rb', line 45 def select_raw.select { |e| e.selected? }.map{ |e| e.text} end |