Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
  2. from com.android.monkeyrunner.easy import EasyMonkeyDevice, By
  3.  
  4. device = MonkeyRunner.waitForConnection()
  5. easy_device = EasyMonkeyDevice(device)
  6.  
  7. easy_device.touch(By.id('action_search'), MonkeyDevice.DOWN_AND_UP)
  8.  
  9. <menu xmlns:android="http://schemas.android.com/apk/res/android"
  10. xmlns:app="http://schemas.android.com/apk/res-auto"
  11. xmlns:tools="http://schemas.android.com/tools"
  12. tools:context=".Cities" >
  13. <item android:id="@+id/action_search"
  14. android:title="@string/search_label"
  15. android:icon="@android:drawable/ic_menu_search"
  16. app:showAsAction="ifRoom"
  17. app:actionViewClass="android.support.v7.widget.SearchView" />
  18. </menu>
  19.  
  20. easy_device.touch(By.id('action_search'), MonkeyDevice.DOWN_AND_UP)
  21. ValueError: View not found: <com.android.monkeyrunner.easy.By object at 0x2>
  22.  
  23. # it doesn't work by id:
  24. #easy_device.touch(By.id('action_search'), MonkeyDevice.DOWN_AND_UP)
  25. # workaround: click on it by coordinates:
  26. device.touch(int(deviceW*0.87), int(deviceH*0.07), 'DOWN_AND_UP')
  27. MonkeyRunner.sleep(1)
  28. # now the search box is active and the keyboard has popped up
  29.  
  30. # click on the middle of the search box doesn't help:
  31. device.touch(int(deviceW*0.5), int(deviceH*0.07), 'DOWN_AND_UP')
  32. MonkeyRunner.sleep(1)
  33.  
  34. # type doesn't work:
  35. device.type('Bud')
  36. # at this point search box lost the focus
  37.  
  38. # nor does pressing the keys work:
  39. device.press('KEYCODE_B', MonkeyDevice.DOWN_AND_UP)
  40. MonkeyRunner.sleep(1)
  41. device.press('KEYCODE_u', MonkeyDevice.DOWN_AND_UP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement