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 分钟前
[从0开始学Java|第十一天]学生管理系统
java·开发语言
java1234_小锋4 分钟前
分享一套优质的基于Python的房屋数据分析预测系统(scikit-learn机器学习+Flask)
python·数据分析·scikit-learn
CCPC不拿奖不改名8 分钟前
RAG基础:基于LangChain 的文本分割实战+文本分块
人工智能·python·langchain·知识库·改行学it·rag·向量库
代码AI弗森23 分钟前
Git Bash 与 PowerShell:定位差异、使用场景与选择建议
开发语言·git·bash
青春不朽51224 分钟前
TensorFlow 入门指南
人工智能·python·tensorflow
bioinfomatic29 分钟前
对比学习基本原理——以DrugClip为例,从CLIP到DrugClip
人工智能·python
代码游侠34 分钟前
C语言核心概念复习(一)
c语言·开发语言·c++·笔记·学习
蜕变的土豆38 分钟前
grpc-通关速成
开发语言·c++
-To be number.wan39 分钟前
Python数据分析:英国电商销售数据实战
开发语言·python·数据分析