Class: Uia::Element
Instance Method Summary
collapse
element_attr, refreshed_element_attr
Methods included from Finder
#find_child, #find_children, #find_from_root
Constructor Details
#initialize(element) ⇒ Element
Returns a new instance of Element.
16
17
18
19
|
# File 'lib/uia/element.rb', line 16
def initialize(element)
@element = element
@default = lambda { [:unknown] }
end
|
Instance Method Details
#as(pattern) ⇒ Object
89
90
91
92
|
# File 'lib/uia/element.rb', line 89
def as(pattern)
raise UnsupportedPattern.new(pattern, patterns) unless patterns.include? pattern
extend pattern.to_pattern_const
end
|
#click ⇒ Object
102
103
104
105
|
# File 'lib/uia/element.rb', line 102
def click
Library.click(@element)
true
end
|
#click_center ⇒ Object
107
108
109
110
|
# File 'lib/uia/element.rb', line 107
def click_center
Library.click_center(@element)
true
end
|
#control_type ⇒ Object
25
26
27
|
# File 'lib/uia/element.rb', line 25
def control_type
Library::Constants::ControlTypes.find(@default) { |_, v| v == @element.control_type_id }.first
end
|
#drag(info) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/uia/element.rb', line 29
def drag(info)
start_x, start_y = info[:start]
end_x, end_y = info[:end]
left, top = bounding_rectangle
coords = [
left + start_x,
top + start_y,
left + end_x,
top + end_y
]
until focused?
focus
end
Library.drag *coords
end
|
#filter(locator) ⇒ Object
85
86
87
|
# File 'lib/uia/element.rb', line 85
def filter(locator)
descendants.select { |e| e.locators_match? locator }
end
|
#find(locator) ⇒ Object
56
57
58
|
# File 'lib/uia/element.rb', line 56
def find(locator)
find_child(@element, locator)
end
|
#find_all(locator) ⇒ Object
60
61
62
|
# File 'lib/uia/element.rb', line 60
def find_all(locator)
find_children(@element, locator)
end
|
#focus ⇒ Object
112
113
114
|
# File 'lib/uia/element.rb', line 112
def focus
Library.focus(@element)
end
|
#locators_match?(locator) ⇒ Boolean
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/uia/element.rb', line 64
def locators_match?(locator)
locator.all? do |locator, value|
case locator
when :pattern
case value
when Array
!(patterns & value).empty?
else
patterns.include? value
end
else
case value
when Array
value.include? send(locator)
else
send(locator) == value
end
end
end
end
|
#patterns ⇒ Object
98
99
100
|
# File 'lib/uia/element.rb', line 98
def patterns
@element.pattern_ids.map { |id| Library::Constants::Patterns.find(@default) { |_, v| v == id }.first }
end
|
#refresh ⇒ Object
51
52
53
54
|
# File 'lib/uia/element.rb', line 51
def refresh
Library.refresh @element
self
end
|
#send_keys(*keys) ⇒ Object
47
48
49
|
# File 'lib/uia/element.rb', line 47
def send_keys(*keys)
Library.send_keys @element, Keys.encode(keys)
end
|
#with(control_types) ⇒ Object
94
95
96
|
# File 'lib/uia/element.rb', line 94
def with(control_types)
extend control_types.to_control_type
end
|