appium python Click coordinates tap
Sometimes when positioning elements, you resorted to locate or less than 18 class skills, how to do it? (Interview often ask)
would come up with a trick: the coordinates of the location of the point where the elements
tap Usage
1.tap is simulated finger click on page elements general
syntax There are two arguments, the first is the positions, a list of up to five point type, duration is the duration in milliseconds
TAP (Self, the Positions, DURATION = None): Taps ON AN Particular Place with up to Five Fingers, Holding for A Certain Time simulation finger tap (up to five fingers), can be set to hold down the length of time (in milliseconds) : Args: - positions - list type, which is a tuple of objects, up to five. Such as: [(100, 20 is), (100, 60 )] - DURATION - duration of milliseconds, such as: 500 : the Usage: Driver. TAP ([( 100, 20 is), (100, 60), (100, 100)], 500)
Coordinate positioning
1. FIG positioned as "to see" the coordinates of the button, you can see right bonds properties: [374,831] [654,906]
2. Tap the top right of the "Search" button to see the bonds attributes: [615,52] [690,146]
References
# coding:utf-8 from appium import webdriver from time import sleep desired_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) # 点弹出框去看看 driver.tap([(374, 831), (654, 906)], 500) # 返回上一页 driver.back() sleep(2) # 点右上角搜素按钮 driver.tap([(615, 52), (690, 146)], 500)
弊端
通过坐标定位是元素定位的下下下策,实在没办法才用这个,另外如果换了手机分辨率,这个坐标就不能写死了,得算出所在屏幕的比例。