@@ -22,13 +22,23 @@ def type text
22
22
-10 to ensure we're not going outside the window bounds.
23
23
24
24
Swiping inside the keyboard will not dismiss it.
25
+
26
+ var startY = au.mainApp().keyboard().rect().origin.y - 10;
27
+ var endY = au.mainWindow().rect().size.height - 10;
28
+ au.flickApp(0, startY, 0, endY);
29
+
30
+ The above logic has been accepted as part of appium's au.hideKeyboard
31
+ https://github.com/appium/appium-uiauto/blob/dbeb4eedbdea2104751a0d547ac9b2894e0dc567/uiauto/appium/app.js#L902
32
+
33
+ If the 'Done' key exists then that should be pressed to dismiss the keyboard
34
+ because swiping to dismiss works only if such key doesn't exist.
25
35
=end
26
36
# type
27
37
$driver. execute_script %(au.getElement('#{ self . ref } ').setValue('#{ text } ');)
28
38
29
39
$driver. ignore {
30
- # wait 5 seconds for keyboard. if the textfield is disabled then
31
- # setValue will work, however the keyboard will never display
40
+ # wait 5 seconds for a wild keyboard to appear . if the textfield is disabled
41
+ # then setValue will work, however the keyboard will never display
32
42
# because users are normally not allowed to type into it.
33
43
$driver. wait_true ( 5 ) do
34
44
$driver. execute_script %(au.mainApp().keyboard().type() !== 'UIAElementNil')
@@ -37,13 +47,16 @@ def type text
37
47
# dismiss keyboard
38
48
js = <<-JS
39
49
if (au.mainApp().keyboard().type() !== "UIAElementNil") {
40
- var startY = au.mainApp().keyboard().rect().origin.y - 10;
41
- var endY = au.mainWindow().rect().size.height - 10;
42
- au.flickApp(0, startY, 0, endY);
50
+ au.hideKeyboard('Done');
43
51
}
44
52
JS
45
53
46
54
$driver. execute_script js
55
+
56
+ # wait 5 seconds for keyboard to go away
57
+ $driver. wait_true ( 5 ) do
58
+ $driver. execute_script %(au.mainApp().keyboard().type() === 'UIAElementNil')
59
+ end
47
60
}
48
61
end # def type
49
62
end # Selenium::WebDriver::Element.class_eval
0 commit comments