Class: SK::Dropdown

Inherits:
Element show all
Defined in:
lib/dropdown.rb

Instance Attribute Summary

Attributes inherited from Element

#el, #locator

Instance Method Summary collapse

Methods inherited from Element

#children, #displayed?, #enabled?, #exists?, #find, #find_child_el, #html, #parent_el, #search, #text, #to_s

Constructor Details

#initialize(locator) ⇒ Dropdown

Returns a new instance of Dropdown.



3
4
5
6
7
# File 'lib/dropdown.rb', line 3

def initialize(locator)
  super(locator) # creates the el and locator via 
  SK::Trace.warn "Dropdown failed to initialize. locator = #{locator}" unless el
  @options = el.find_elements(tag_name: "option")  
end

Instance Method Details

#select(value) ⇒ Object



9
10
11
# File 'lib/dropdown.rb', line 9

def select(value)
  select_by('text',value)
end

#select_by(attr, value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/dropdown.rb', line 13

def select_by(attr,value)
  @options.each do |option|
    optval = option.attribute(attr)
    # trace "looking at #{optval}"
    if optval == value
      option.click
      break
    end
  end
end

#select_index(index) ⇒ Object



24
25
26
27
28
# File 'lib/dropdown.rb', line 24

def select_index(index)
  n = [@options.length-1,index].min
  @options[n].click
  return @options[n].attribute('text')
end