Class: CapybaraPageObject::SelectListElement

Inherits:
Element
  • Object
show all
Defined in:
lib/capybara_page_object/elements/select_list_element.rb

Instance Attribute Summary

Attributes inherited from Element

#element, #page

Instance Method Summary collapse

Methods inherited from Element

#attribute, #class, #enabled?, #focus, #html, #initialize, #method_missing, #native, #parent, #respond_to_missing?, #scroll_into_view, #within

Constructor Details

This class inherits a constructor from CapybaraPageObject::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CapybaraPageObject::Element

Instance Method Details

#clearObject



16
17
18
# File 'lib/capybara_page_object/elements/select_list_element.rb', line 16

def clear
  selected_options.each(&:unselect_option)
end

#select_value(value) ⇒ Object



26
27
28
29
30
# File 'lib/capybara_page_object/elements/select_list_element.rb', line 26

def select_value(value)
  within do
    all(:css, "option[@value=#{value}]").each(&:select_option)
  end
end

#selected?(value_or_text) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
# File 'lib/capybara_page_object/elements/select_list_element.rb', line 4

def selected?(value_or_text)
  option = selected_option
  option.value == value_or_text ||
    option.text == value_or_text
end

#selected_optionObject



10
11
12
13
14
# File 'lib/capybara_page_object/elements/select_list_element.rb', line 10

def selected_option
  within do
    first('option[selected]')
  end
end

#selected_optionsObject



20
21
22
23
24
# File 'lib/capybara_page_object/elements/select_list_element.rb', line 20

def selected_options
  within do
    all('option[selected]')
  end
end

#selected_valuesObject



32
33
34
# File 'lib/capybara_page_object/elements/select_list_element.rb', line 32

def selected_values
  selected_options.map(&:value)
end