module PageObject::Platforms::SeleniumWebDriver::SelectList

Public Instance Methods

[](idx) click to toggle source

Return the PageObject::Elements::Option for the index provided. Index is zero based.

@return [PageObject::Elements::Option]

# File lib/page-object/platforms/selenium_webdriver/select_list.rb, line 12
def [](idx)
  options[idx]
end
clear() click to toggle source

Deselect all selected options.

# File lib/page-object/platforms/selenium_webdriver/select_list.rb, line 80
def clear
  find_options.select { |e| e.selected? }.each { |o| o.click }
end
include?(value) click to toggle source

Returns true if the select list has one or more options where text or label matches the given value.

@param [String, Regexp] value A value. @return [Boolean]

# File lib/page-object/platforms/selenium_webdriver/select_list.rb, line 63
def include?(value)
  find_options.any? { |e| e.text == value }
end
options() click to toggle source

Return an array of Options contained in the select list.

@return [array of PageObject::Elements::Option]

# File lib/page-object/platforms/selenium_webdriver/select_list.rb, line 40
def options
  find_options.map { |e| ::PageObject::Elements::Option.new(e, :platform => :selenium_webdriver) }
end
select(value) click to toggle source

Select a value from the list

# File lib/page-object/platforms/selenium_webdriver/select_list.rb, line 19
def select(value)
  find_options.find do |option|
    option.text == value
  end.click
end
select_value(value) click to toggle source

Select the option(s) whose value attribute matches the given string

# File lib/page-object/platforms/selenium_webdriver/select_list.rb, line 29
def select_value(value)
  options = find_options.find_all do |option|
    option.attribute('value') == value
  end
  options.each {|opt| opt.click}
end
selected?(value) click to toggle source

Returns true if any of the selected options' text match the given value.

@param [String, Regexp] value A value. @return [Boolean]

# File lib/page-object/platforms/selenium_webdriver/select_list.rb, line 72
def selected?(value)
  selected = find_options.select { |e| e if e.selected? }
  selected.any? { |e| e.text == value }
end
selected_options() click to toggle source

@return [Array<String>] An array of strings representing the text of the currently selected options.

# File lib/page-object/platforms/selenium_webdriver/select_list.rb, line 47
def selected_options
  find_options.map { |e| e.text if e.selected? }.compact
end
selected_values() click to toggle source

@return [Array<String>] An array of strings representing the value of the currently selected options.

# File lib/page-object/platforms/selenium_webdriver/select_list.rb, line 54
def selected_values
  find_options.map { |e| e.attribute('value') if e.selected? }.compact
end

Private Instance Methods

find_options() click to toggle source
# File lib/page-object/platforms/selenium_webdriver/select_list.rb, line 86
def find_options
  element.find_elements(:xpath, child_xpath)
end