Class: RAutomation::Adapter::WinFfi::Control
- Inherits:
-
Object
- Object
- RAutomation::Adapter::WinFfi::Control
show all
- Includes:
- WaitHelper
- Defined in:
- lib/rautomation/adapter/win_ffi/control.rb
Instance Method Summary
collapse
Constructor Details
#initialize(window, locators) ⇒ Control
Note:
this method is not meant to be accessed directly
Creates the control object.
17
18
19
20
|
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 17
def initialize(window, locators)
@window = window
(locators)
end
|
Instance Method Details
#assert_enabled
73
74
75
|
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 73
def assert_enabled
raise "Cannot interact with disabled control #{@locators.inspect} on window #{@window.locators.inspect}!" if disabled?
end
|
#click
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 22
def click
assert_enabled
clicked = false
wait_until do
hwnd = Functions.control_hwnd(@window.hwnd, @locators)
@window.activate
@window.active? &&
Functions.set_control_focus(hwnd) &&
Functions.control_click(hwnd) &&
clicked = true
block_given? ? yield : clicked && !exist?
end
end
|
#disabled? ⇒ Boolean
46
47
48
|
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 46
def disabled?
Functions.unavailable?(Functions.control_hwnd(@window.hwnd, @locators))
end
|
#enabled? ⇒ Boolean
42
43
44
|
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 42
def enabled?
!disabled?
end
|
#exist? ⇒ Boolean
Also known as:
exists?
38
39
40
|
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 38
def exist?
!!Functions.control_hwnd(@window.hwnd, @locators)
end
|
#has_focus? ⇒ Boolean
50
51
52
|
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 50
def has_focus?
Functions.has_focus?(Functions.control_hwnd(@window.hwnd, @locators))
end
|
#matches_type(clazz)
67
68
69
|
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 67
def matches_type(clazz)
UiaDll::current_control_type(uia_control(@locators[:id])) == clazz
end
|
#set_focus
54
55
56
57
58
|
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 54
def set_focus
assert_enabled
uia_control = UiaDll::element_from_handle(Functions.control_hwnd(@window.hwnd, @locators))
UiaDll::set_focus(uia_control)
end
|
#uia_control(automation_id)
60
61
62
63
64
65
|
# File 'lib/rautomation/adapter/win_ffi/control.rb', line 60
def uia_control(automation_id)
uia_window = UiaDll::element_from_handle(@window.hwnd) uia_element = UiaDll::find_child_by_id(uia_window, automation_id.to_s)
fail "Cannot find UIAutomationElement" if uia_element.nil?
uia_element
end
|