appium 实战问题 播放视频时无法定位到元素

背景

在做UI自动化时,有播放详情页的用例,但是发现视频在播放的时候无法定位到元素或者很慢,了解到appium在动态的页面实时获取布局元素导致定位变慢。所以只能将视频暂停在操作元素,点击到暂停按钮又是个问题,通过adb 点击坐标的话,不同设备就会成为问题。

解决思路

通过 adb shell uiautomator dump 到xml文件push到电脑端,再进行xml解析,识别到指定的元素,获取到当前元素坐标,再让adb进行点击操作。

python 复制代码
import xml.etree.ElementTree as ET
# name是当前操作暂停键元素id名称
def dump_xml_return_tap(name):
    os.system("adb shell uiautomator dump /sdcard/layout.xml")
    path = os.path.join(BasePath, "xmls")
    path_file = os.path.join(path, "{}.xml".format(name))
    os.system("adb pull /sdcard/layout.xml {}".format(path_file))

    tree = ET.parse(path_file)
    root = tree.getroot()
    for i in root.findall(".//node"):
        if name in i.get("resource-id"):
            coord = i.get("bounds")
            res = coord.strip("[]")
            res = res.replace("][", ",").split(",")
            logger.info(res)
            x = int((int(res[0]) + int(res[2])) / 2)
            y = int((int(res[1]) + int(res[3])) / 2)
            logger.info("x:{},y:{}".format(x, y))
            return {"x": x, "y": y}```
相关推荐
从零开始学习人工智能3 小时前
【踩坑实录】WSL2 解决 onnxruntime\-gpu ImportError: libcudart\.so\.13 无 CUDA13 运行库问题
python
WWJA王文举4 小时前
I²C通信完整流程详解:START、地址、ACK、数据、Repeated START和STOP一次讲透
c语言·开发语言
卷无止境4 小时前
在 awesome-fastapi 里,哪些库值得一看?
后端·python
zhanghaha13144 小时前
Python进阶教程:6_JSON 数据解析 —— 新手完全指南
开发语言·python·json
Python私教5 小时前
API 输出模型怎么设计:从 model_dump() 到显式展示层
python·fastapi
Python私教5 小时前
本地 AI 工具服务该绑定 127.0.0.1 还是 0.0.0.0?
python·fastapi
卷无止境5 小时前
FastAPI 的Admin面板生态
后端·python
qq_448011166 小时前
C语言中的动态内存分配
c语言·开发语言·php
ctlover6 小时前
Streamlit 框架
python
ι:6 小时前
MATLAB 与 Python 搭建无人机地面站:优势、劣势与选型逻辑
python·matlab·无人机