Search code examples
androidmonkeyrunner

How to click a view of android program through MonkeyRunner?


I want to use MonkeyRunner to test the compatibility of my android program for a list of devices with different screen resolutions. I need to click a view, but the view is not in the same position for different resolutions. How can I get the position of it or do something else to click it? NEED your help!


Solution

  • I know it's a little late, but you can use hierarchyviewer in android sdk to get the view id.

    Then, in your script, use this:

    from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice  
    from com.android.monkeyrunner.easy import EasyMonkeyDevice, By  
    
    device = MonkeyRunner.waitForConnection()  
    easy_device = EasyMonkeyDevice(device)  
    
    # Start your android app
    
    # touch the view by id
    
    easy_device.touch(By.id('view_id'), MonkeyDevice.DOWN_AND_UP)
    

    Later edit: thanks to dtmilano and AndroidViewClient, I was able to do the clicks on views as needed. The link is here: https://github.com/dtmilano/AndroidViewClient