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}```
相关推荐
Bug改不动了9 分钟前
LangGraph基础知识(MemorySaver/SqliteSaver )(三)
python·langgraph
这里有鱼汤1 小时前
Python初学者常犯的错误汇总,建议收藏
后端·python
Johny_Zhao18 小时前
CentOS Stream 8 高可用 Kuboard 部署方案
linux·网络·python·网络安全·docker·信息安全·kubernetes·云计算·shell·yum源·系统运维·kuboard
站大爷IP18 小时前
精通einsum():多维数组操作的瑞士军刀
python
站大爷IP19 小时前
Python与MongoDB的亲密接触:从入门到实战的代码指南
python
Roc-xb20 小时前
/etc/profile.d/conda.sh: No such file or directory : numeric argument required
python·ubuntu·conda
粟悟饭&龟波功20 小时前
Java—— ArrayList 和 LinkedList 详解
java·开发语言
冷雨夜中漫步20 小时前
Java中如何使用lambda表达式分类groupby
java·开发语言·windows·llama
a45763687620 小时前
Objective-c Block 面试题
开发语言·macos·objective-c
Cai junhao20 小时前
【Qt】Qt控件
开发语言·c++·笔记·qt