Using ADB to access a particular UI control on the screen

后端 未结 5 1210
时光说笑
时光说笑 2021-02-01 07:12

Is it possible for adb shell console to access an Android app\'s specific button using its id? or text?

I\'m trying to automate the button click on the dev

5条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 07:55

    if me, i use python to do that, combine cmd command with subprocess.Popen, the script would be:

    from subprocess import Popen, PIPE
    
    import os
    
    adbpath = r'YOUR ADB DIR'
    adbfile = 'adb.exe'
    adb = os.path.join(adbpath, adbfile)
    
    def tap(a):
        cor = a
        t = Popen([adb, 'shell', 'input', 'tap', str(a[0]), str(a[1])])
    
    #i give you extra script
    
    def swipe(a, b):
         first = a
         last = b
         sab = Popen([adb, 'shell', 'input', 'swipe', str(first[0]), str(first[1]), str(last[0]), str(last[1]), '200'])
    

    then when you have a button coord to tap just do this:

    ok_coord = 122,137
    tap(ok_coord)
    

    when you want to swipe:

    coord1 = 122,373
    coord2 = 122,26
    swipe(coord1, coord2)
    

    to get the coordinate of button or a point, use 'uiautomatorviewer.bat' that exists in folder 'sdk\tools\bin'

    or you can use apricot, erm3nda or Vinicius Dantas method,

提交回复
热议问题