Airtest 的 Poco 框架中,offspring()

offspring() 的意思是:

递归查找子孙控件 ,即:从当前控件开始,查找它的"子控件"+"孙控件"+"重孙控件"... 直到找到匹配的目标控件。


📌 举例说明:

假设一个控件层级结构如下:

父容器 A

├── 子容器 B

│ └── TextView(id="title")

如果你从控件 A 出发:

  • A.child("title") ❌ 找不到,因为 title 不是 直接子控件

  • A.offspring("title") ✅ 可以找到,因为 title 是 A 的子孙控件


🆚 和其他方法对比

方法 作用 是否递归查找
children() 只查找 直接子控件 否 ❌
child("xxx") 获取名为 "xxx" 的直接子控件 否 ❌
offspring("xxx") 查找名为 "xxx" 的所有子孙控件 是 ✅
descendant("xxx") (别名,和 offspring() 类似) 是 ✅

✅ 实用示例

python 复制代码
# 获取列表容器
list_view = poco("com.example:id/news_list")

# 获取列表中第一个新闻项
first_item = list_view.children()[0]

# 在第一个新闻项中递归查找标题文本
title = first_item.offspring("com.example:id/title").get_text()
print(f"新闻标题: {title}")

✅ 总结一句话:

offspring("xxx") 就像是从当前控件出发,递归往下找"全家族里叫 xxx 的人",无论隔了几代都能找。

相关推荐
映翰通朱工2 小时前
Windows 上位机 + EC3320:USB 转 CAN 通信实测(从接线到 SSH 收包)
windows·stm32·ssh
我是Superman丶2 小时前
【2026亲测】Wireshark安装教程 Windows系统|下载安装、Npcap配置及首次抓包
windows·测试工具·wireshark
sg_knight4 小时前
Codex CLI 安装全攻略:macOS / Linux / Windows(WSL2)三端实战
linux·windows·macos·openai·ai编程·coding·codex
趣味科技1 天前
记录修复EAGET忆捷移动硬盘损坏
windows·数据分析·硬件工程
我命由我123451 天前
Java 开发 - List subList 方法
java·windows·操作系统·list·intellij-idea·idea·intellij idea
吃辣我第一1 天前
监听SHP目录自动注册SuperMap iServer地图服务(Windows版)
windows·iserver·shapefile
程序员老陆1 天前
FFmpeg6 在 Windows 打开麦克风并录成 PCM:不走 Qt Multimedia,也不碰 WASAPI
windows·ffmpeg·音视频·pcm
chushiyunen1 天前
神雕武功排名
windows
酩酊仙人1 天前
Windows Server部署django
windows·django·sqlite
蓝斯4972 天前
从.到实现一个Windows上的虚拟hid键盘设备
windows·单片机·计算机外设