AndroidViewClient icon indicating copy to clipboard operation
AndroidViewClient copied to clipboard

long press touch on view or position

Open imiten opened this issue 12 years ago • 3 comments

Hi,

I am unable find API in AVC to do long press on screen. I have device running API 17. I read adbclient.py code and for API <=17 duration and count for drag are ignored.

I thought may be I could use drag keeping position same as workaround.

AVC AndroidViewClient-6cd170e65a8869fd9d5915a984342aa3b8937ce7

If I do cmd = 'input tap ' + str(center[0]) + ' ' + str(center [1]) it will simulate touch but do not know how to make it simulate long press touch.

is longClick possible with AVC ?

do I need to fallback to monkeyrunner based script for it as I see mentioned at places that following snippet should work for long press.

from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice import time device = MonkeyRunner.waitForConnection() device.touch(100, 100, MonkeyDevice.DOWN) time.sleep(2); device.touch(100, 100, MonkeyDevice.UP)

so if I want to add above code in current non-monkeyrunner script can I do that ? I mean can I mix old monkeyrunner and current viewclient based codes ?

I am able to use subprocess.call as below as workaround: call(['monkeyrunner.bat', 'd:\work\testing\avc\longpress.py'])

Regards,

miten.

imiten avatar Oct 12 '13 10:10 imiten

The following workaround is working for me:

adbclient.py

def touch(self, x, y, eventType=DOWN_AND_UP):
    if eventType == DOWN_AND_UP:
        self.shell('input tap %d %d' % (x, y))
    elif eventType == DOWN:
        self.drag((x,y), (x,y), 1, 1)

For API > 17 I had to modify drag function according to the suggestion in https://github.com/dtmilano/AndroidViewClient/issues/63

amsterr avatar Nov 29 '13 16:11 amsterr

I have used the same function as @amsterr and it worked for me too, however there is another simple way to do it if you know the coordinates, but basically is the same thing as the other solution.

device.drag((x, y), (x, y), 2000, 1)

luisvasconcelos avatar Jan 28 '16 18:01 luisvasconcelos

I have used the same function as @amsterr and it worked for me too, however there is another simple way to do it if you know the coordinates, but basically is the same thing as the other solution.

device.drag((x, y), (x, y), 2000, 1)

works ok, but the delay is in seconds, it would be for 2 seconds:

device.drag((x, y), (x, y), 2, 1)

ignaciotcrespo avatar May 19 '21 08:05 ignaciotcrespo