# 坐标测试 import uiautomator2 as u2 # 连接设备 d = u2.connect() # 获取屏幕的尺寸 width, height = d.window_size() print(f"屏幕尺寸: {width}x{height}") # 使用xpath定位按钮并获取其位置信息 # button = d.xpath('//*[@content-desc="买入/开多"]').get() # if button: # # bounds返回(left, top, right, bottom)坐标 # print(f"按钮坐标(left, top, right, bottom): {button.bounds}") # top_distance = button.bounds[1] # top坐标即是距离顶部的距离 # print(f"按钮距离顶部: {top_distance}像素") # 屏幕向上滚动以查看底部内容 (从屏幕下方向上滑动) # fx, fy: 滑动的起始坐标点 # # # fx: 起始点的 x 坐标 # fy: 起始点的 y 坐标 # tx, ty: 滑动的目标坐标点 # # # tx: 目标点的 x 坐标 # ty: 目标点的 y 坐标 # duration: 滑动持续时间(以秒为单位) # # 可选参数,默认为 None # 用于控制滑动的速度 # 如果同时设置了 steps 参数,duration 将被忽略 # steps: 滑动的步数 # # # 可选参数,默认为 None # 每一步大约需要 5 毫秒 # 例如:设置 steps=200,整个滑动过程将持续约 1 秒(200 * 5ms = 1000ms) # 当设置了 steps 时,会忽略 duration 参数 # d.swipe(width // 2, height * 0.8, width // 2, height * 0.1) # buttons = d.xpath('//*[starts-with(@content-desc, "持仓")]').all() # button = d.xpath('//*[@content-desc="买入/开多"]').get() button = d.xpath('//*[@content-desc="市价全平"]').get() print(f"第一个 坐标(left, top, right, bottom): {button.bounds}") buttons = d.xpath('//*[@content-desc="市价全平"]').all() for idx, button in enumerate(buttons): print(f"按钮 {idx + 1} 坐标(left, top, right, bottom): {button.bounds}") # if button: # # bounds返回(left, top, right, bottom)坐标 # print(f"按钮坐标(left, top, right, bottom): {button.bounds}") # top_distance = button.bounds[1] # top坐标即是距离顶部的距离 # print(f"按钮距离顶部: {top_distance}像素") # d.swipe(width // 2, height * 0.8, width // 2, height * 0.3, duration=0.5)