Class: Sapphire::WebAbstractions::DropDown

Inherits:
Control show all
Defined in:
lib/sapphire/WebAbstractions/Controls/DropDown.rb

Instance Attribute Summary

Attributes inherited from Control

#control, #found_by_type, #found_by_value

Instance Method Summary collapse

Methods inherited from Control

#Click, #Equals, #Evaluate, #Find, #FindAll, #FindWithoutWait, #GetValue, #In, #MouseOver, #Substitute, #Visible, #initialize

Constructor Details

This class inherits a constructor from Sapphire::WebAbstractions::Control

Instance Method Details

#ClearObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/sapphire/WebAbstractions/Controls/DropDown.rb', line 47

def Clear
  @array.each do |item|
    if item.has_key? :default
      self.Set(item[:default])
      return
    end
  end

  raise "no :default set for DropDown"
end

#Contain(expected_value) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sapphire/WebAbstractions/Controls/DropDown.rb', line 29

def Contain(expected_value)
  ddl = self.Find
  items = ddl.find_elements(:tag_name, "option")
  items.each do |item|
    if item.text == expected_value
      return ControlEvaluation.new(item.text, expected_value, self)
    end
  end

  return ControlEvaluation.new("Value not found in list", expected_value, self)
end

#Count(value) ⇒ Object



41
42
43
44
45
# File 'lib/sapphire/WebAbstractions/Controls/DropDown.rb', line 41

def Count(value)
  ddl = self.Find
  items = ddl.find_elements(:tag_name, "option")
  return ControlEvaluation.new(items.count, value, self)
end

#SelectedObject



8
9
10
11
# File 'lib/sapphire/WebAbstractions/Controls/DropDown.rb', line 8

def Selected
  text = self.Find
  text.value
end

#Selected=(value) ⇒ Object



4
5
6
# File 'lib/sapphire/WebAbstractions/Controls/DropDown.rb', line 4

def Selected= (value)
  Set(value)
end

#Set(value) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/sapphire/WebAbstractions/Controls/DropDown.rb', line 21

def Set(value)
  text = self.Find
  options = text.find_elements(:tag_name, "option")
  selection = options.find{|o| o.text == value.to_s}
  raise "could not find the value " + value.to_s if selection.nil?
  selection.click
end

#TextObject



13
14
15
16
17
18
19
# File 'lib/sapphire/WebAbstractions/Controls/DropDown.rb', line 13

def Text
  text = self.Find
  val = text.attribute("value")
  options = text.find_elements(:tag_name, "option")
  selection = options.find{|o| o.attribute("value") == val.to_s}
  selection.text
end