Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
- from com.android.monkeyrunner.easy import EasyMonkeyDevice, By
- device = MonkeyRunner.waitForConnection()
- easy_device = EasyMonkeyDevice(device)
- easy_device.touch(By.id('action_search'), MonkeyDevice.DOWN_AND_UP)
- <menu xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- tools:context=".Cities" >
- <item android:id="@+id/action_search"
- android:title="@string/search_label"
- android:icon="@android:drawable/ic_menu_search"
- app:showAsAction="ifRoom"
- app:actionViewClass="android.support.v7.widget.SearchView" />
- </menu>
- easy_device.touch(By.id('action_search'), MonkeyDevice.DOWN_AND_UP)
- ValueError: View not found: <com.android.monkeyrunner.easy.By object at 0x2>
- # it doesn't work by id:
- #easy_device.touch(By.id('action_search'), MonkeyDevice.DOWN_AND_UP)
- # workaround: click on it by coordinates:
- device.touch(int(deviceW*0.87), int(deviceH*0.07), 'DOWN_AND_UP')
- MonkeyRunner.sleep(1)
- # now the search box is active and the keyboard has popped up
- # click on the middle of the search box doesn't help:
- device.touch(int(deviceW*0.5), int(deviceH*0.07), 'DOWN_AND_UP')
- MonkeyRunner.sleep(1)
- # type doesn't work:
- device.type('Bud')
- # at this point search box lost the focus
- # nor does pressing the keys work:
- device.press('KEYCODE_B', MonkeyDevice.DOWN_AND_UP)
- MonkeyRunner.sleep(1)
- device.press('KEYCODE_u', MonkeyDevice.DOWN_AND_UP)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement