Class: Capybara::Select2::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara_select2.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_context, options = {}) ⇒ Element

Returns a new instance of Element.



8
9
10
11
12
13
# File 'lib/capybara_select2.rb', line 8

def initialize(page_context, options = {})
  self.page = page_context
  self.search_enabled = !!options[:search]
  self.multiselect = !!options[:multiple]
  find_container(options.slice(:from, :xpath))
end

Instance Attribute Details

#containerObject

Returns the value of attribute container.



6
7
8
# File 'lib/capybara_select2.rb', line 6

def container
  @container
end

#multiselectObject

Returns the value of attribute multiselect.



6
7
8
# File 'lib/capybara_select2.rb', line 6

def multiselect
  @multiselect
end

#pageObject

Returns the value of attribute page.



6
7
8
# File 'lib/capybara_select2.rb', line 6

def page
  @page
end

#search_enabledObject

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_classObject



15
16
17
# File 'lib/capybara_select2.rb', line 15

def drop_container_class
  if search_enabled then '.select2-results' else '.select2-drop' end
end

#initiate!(value) ⇒ Object



23
24
25
26
# File 'lib/capybara_select2.rb', line 23

def initiate!(value)
  focus!
  search!(value) if search_enabled
end

#select_match!Object



19
20
21
# File 'lib/capybara_select2.rb', line 19

def select_match!
  page.find(:css, drop_container_class).find(:css, ".select2-match").click
end