? # Preface:
Sometimes when positioning elements, you have resorted to 18 classes of martial arts or not located, how to do? (interviews are often asked)
Then take the trick: coordinates of the location of the point element
Tap usage
1.TAP is analog finger click, General page elements
The syntax has two parameters, the first is positions, is the list type up to five points, the duration is the duration, unit milliseconds
tap(self, positions, duration=None): on an particular place with up to five fingers, holding for a certain time 模拟手指点击(最多五个手指),可设置按住时间长度(毫秒) :Args: - positions - list类型,里面对象是元组,最多五个。如:[(100, 20), (100, 60)] - duration - 持续时间,单位毫秒,如:500 :Usage: driver.tap([(100, 20), (100, 60), (100, 100)], 500)
Coordinate positioning
1. If you position "go to see" The coordinates of this button, you can see the right bonds property: [374,831][654,906]
2. Click the "Search" button in the upper right corner to view the Bonds properties: [615,52][690,146]
Reference case
# Coding:utf-8From AppiumImport WebdriverFrom timeImport Sleepdesired_caps= {' PlatformName ':' Android ',' DeviceName ':' 127.0.0.1:62001 ',' Platformversion ':' 4.4.2 ',' Apppackage ': ' com.baidu.yuedu ', Appactivity ': ' com.baidu.yuedu.splash.SplashActivity '}driver = webdriver. Remote ( ' Http://127.0.0.1:4723/wd/hub ', desired_caps) sleep ( 5) # point pop-up box to see Driver.tap ([(374, 831), ( Span class= "DV" >654, 906)], 500) # Return to previous page Driver.back () Sleep (2) # point upper right corner of the search button Driver.tap ([ Span class= "DV" >615, 52), (690, 146)], 500)
Disadvantages
Coordinate positioning is the bottom of the element positioning, there is no way to use this, in addition, if the phone resolution, the coordinates can not be written dead, to calculate the proportion of the screen.
Appium+python Automation 26-Analog gesture Click Coordinates (TAP) "Reprint"