Class: Capybara::Select2::Element
- Inherits:
-
Object
- Object
- Capybara::Select2::Element
- Defined in:
- lib/capybara_select2.rb
Instance Attribute Summary collapse
-
#container ⇒ Object
Returns the value of attribute container.
-
#drop_container ⇒ Object
Returns the value of attribute drop_container.
-
#multiselect ⇒ Object
Returns the value of attribute multiselect.
-
#options ⇒ Object
Returns the value of attribute options.
-
#page ⇒ Object
Returns the value of attribute page.
-
#search_enabled ⇒ Object
Returns the value of attribute search_enabled.
Instance Method Summary collapse
- #drop_container_class(value) ⇒ Object
-
#initialize(page_context, options = {}) ⇒ Element
constructor
A new instance of Element.
- #initiate! ⇒ Object
- #select_match!(value) ⇒ Object
Constructor Details
#initialize(page_context, options = {}) ⇒ Element
Returns a new instance of Element.
8 9 10 11 12 13 14 |
# File 'lib/capybara_select2.rb', line 8 def initialize(page_context, = {}) self.page = page_context self.= self.search_enabled = !![:search] self.multiselect = !![:multiple] find_container(.slice(:from, :xpath)) end |
Instance Attribute Details
#container ⇒ Object
Returns the value of attribute container.
6 7 8 |
# File 'lib/capybara_select2.rb', line 6 def container @container end |
#drop_container ⇒ Object
Returns the value of attribute drop_container.
6 7 8 |
# File 'lib/capybara_select2.rb', line 6 def drop_container @drop_container end |
#multiselect ⇒ Object
Returns the value of attribute multiselect.
6 7 8 |
# File 'lib/capybara_select2.rb', line 6 def multiselect @multiselect end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/capybara_select2.rb', line 6 def end |
#page ⇒ Object
Returns the value of attribute page.
6 7 8 |
# File 'lib/capybara_select2.rb', line 6 def page @page end |
#search_enabled ⇒ Object
Returns the value of attribute search_enabled.
6 7 8 |
# File 'lib/capybara_select2.rb', line 6 def search_enabled @search_enabled end |
Instance Method Details
#drop_container_class(value) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/capybara_select2.rb', line 16 def drop_container_class(value) if .has_key? :search page.find(:xpath, "//body").find(".select2-search input.select2-search__field").set(value) page.execute_script(%|$("input.select2-search__field:visible").keyup();|) ".select2-results" elsif page.find(:xpath, "//body").has_selector?(".select2-dropdown") # select2 version 4.0 ".select2-dropdown" else ".select2-drop" end end |
#initiate! ⇒ Object
40 41 42 |
# File 'lib/capybara_select2.rb', line 40 def initiate! focus! end |
#select_match!(value) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/capybara_select2.rb', line 29 def select_match!(value) [value].flatten.each do |value| if page.find(:xpath, "//body").has_selector?("#{drop_container_class(value)} li.select2-results__option") # select2 version 4.0 page.find(:xpath, "//body").find("#{drop_container_class(value)} li.select2-results__option", text: value).click else page.find(:xpath, "//body").find("#{drop_container_class(value)} li.select2-result-selectable", text: value).click end end end |