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}```
相关推荐
码智社36 分钟前
AES加密原理详解及Java实现加解密实战
java·开发语言
AI云海38 分钟前
python 列表、元组、集合和字典
开发语言·python
二十雨辰1 小时前
[爬虫]-Urllib
爬虫·python
萧瑟余晖2 小时前
JDK 26 新特性详解
java·开发语言
马优晨2 小时前
Freemarker 完整讲解(后端 Java 模板引擎)
java·开发语言·freemarker·freemarker 完整讲解·freemarker模板引擎
玉鸯3 小时前
Agent Hook:在概率推理之上,为 Agent 叠加确定性控制
python·langchain·agent
weixin_446260853 小时前
HACO:面向动态部署环境的对冲式智能计算可靠多智能体调度框架
后端·python·flask
我的xiaodoujiao4 小时前
API 接口自动化测试详细图文教程学习系列32--Allure测试报告2
python·学习·测试工具·pytest
人邮异步社区4 小时前
怎么把C语言学到精通?
c语言·开发语言