Skip to content

Commit 1f0428d

Browse files
Fix keyboard race condition
After typing, the keyboard does not instantly appear. Wait for it to appear, and then dismiss the keyboard.
1 parent c99ed34 commit 1f0428d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/appium_lib/ios/patch.rb

+9-3
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,22 @@ def type text
1616
1717
Swiping inside the keyboard will not dismiss it.
1818
=end
19-
js = <<-JS
20-
au.getElement('#{self.ref}').setValue('#{text}');
19+
# type
20+
execute_script %(au.getElement('#{self.ref}').setValue('#{text}');)
21+
22+
# wait for keyboard
23+
wait_true { execute_script %(au.mainApp.keyboard().type() !== 'UIAElementNil') }
2124

25+
# dismiss keyboard
26+
js = <<-JS
2227
if (au.mainApp.keyboard().type() !== "UIAElementNil") {
2328
var startY = au.mainApp.keyboard().rect().origin.y - 10;
2429
var endY = au.mainWindow.rect().size.height - 10;
2530
au.flickApp(0, startY, 0, endY);
2631
}
2732
JS
28-
@driver.execute_script js
33+
34+
execute_script js
2935
end
3036
end
3137
end

0 commit comments

Comments
 (0)