Module: PageObject::Platforms::SeleniumWebDriver::SelectList

Defined in:
lib/page-object/platforms/selenium_webdriver/select_list.rb

Instance Method Summary collapse

Instance Method Details

#[](idx) ⇒ PageObject::Elements::Option

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



12
13
14
# File 'lib/page-object/platforms/selenium_webdriver/select_list.rb', line 12

def [](idx)
  options[idx]
end

#include?(value) ⇒ Boolean

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

Parameters:

  • value (String, Regexp)

    A value.

Returns:

  • (Boolean)


43
44
45
# File 'lib/page-object/platforms/selenium_webdriver/select_list.rb', line 43

def include?(value)
  find_options.any? { |e| e.text == value }
end

#optionsarray of PageObject::Elements::Option

Return an array of Options contained in the select lit.

Returns:



27
28
29
# File 'lib/page-object/platforms/selenium_webdriver/select_list.rb', line 27

def options
  find_options.map { |e| ::PageObject::Elements::Option.new(e, :platform => :selenium_webdriver) }
end

#select(value) ⇒ Object

Select a value from the list



19
20
21
# File 'lib/page-object/platforms/selenium_webdriver/select_list.rb', line 19

def select(value)
  element.send_keys(value)
end

#selected?(value) ⇒ Boolean

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

Parameters:

  • value (String, Regexp)

    A value.

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/page-object/platforms/selenium_webdriver/select_list.rb', line 52

def selected?(value)
  selected = find_options.select { |e| e if e.selected? }
  selected.any? { |e| e.text == value }
end

#selected_optionsArray<String>

Returns An array of strings representing the text value of the currently selected options.

Returns:

  • (Array<String>)

    An array of strings representing the text value of the currently selected options.



34
35
36
# File 'lib/page-object/platforms/selenium_webdriver/select_list.rb', line 34

def selected_options
  find_options.map { |e| e.text if e.selected? }.compact
end