当前位置: 首页 > news >正文

app爬虫中的Airtest元素存在或等待

app爬虫中的Airtest元素存在或等待

一. poco等待

等待无错误
等待元素10秒。如果它没有出现,则不会引发任何错误。

poco('xxx').wait(timeout=10)

您还可以在.wait()之后执行一些操作,如click或long_click

poco('xxx').wait(timeout=10).click()
poco('xxx').wait(timeout=10).long_click()

等待错误
等待元素10秒。如果元素未出现,将引发PocoTargetTimeout错误。

poco('xxx').wait_for_appearance(20)
poco('xxx').wait_for_disappearance(20) # wait for disappearance of the element

常见的使用:

from poco.exceptions import PocoTargetTimeout

try:
    poco('xxx').wait_for_appearance(20)
except PocoTargetTimeout:
    # logging...
    # raise ...

等待元素(没有时间设置)
Wait_for_all()将等待所有元素出现。Wait_for_any()将等待,直到任何一个元素出现。

yellow = poco("yellow")
blue = poco("blue")
black = poco("black")

poco.wait_for_all([yellow,blue,black])
# poco.wait_for_any([yellow,blue,black])
poco('xxx').click()  # if the elements above not appeared, this click will not be operated

检查是否存在,不要等待
poco(‘xxx’).exists() 将返回True或False来告诉你元素的当前状态(不会引发错误)。

if poco('xxx').exists():
    # some operations if find the element
else:
    # some operations if not find the element

二. Airtest wait

from airtest.core.api import *
# exist
exists(some_element)  # return True or False
# wait - if not appear, TargetNotFoundError will be raised
wait(some_element, timeout=5)
# wait - the default value of timeout is set by ST.FIND_TIMEOUT
wait(some_element)

相关文章:

  • Docker 容器化(初学者的分享)
  • Map<String, Object> 和 com.fasterxml.jackson.databind.node.ObjectNode区别
  • Python 机器学习入门之K-Means聚类算法
  • SD NAND对比TF卡优势(以CSNP4GCR01-AMW为例)
  • Nmap使用技巧总结
  • AndroidStudio如何设置中文
  • 百度松果20231022作业
  • Docker数据管理、端口映射、容器互联
  • 施密特正交化
  • 在ESP32-Arduino开发中添加其它Arduino库
  • Mac 远程桌面软件
  • WuThreat身份安全云-TVD每日漏洞情报-2023-10-16
  • 【BIGRU预测】基于双向门控循环单元的多变量时间序列预测(Matlab代码实现)
  • 智慧公厕管理系统:让公厕更智能、更高效的利器
  • 分类预测 | MATLAB实现SSA-CNN-LSTM麻雀算法优化卷积长短期记忆神经网络数据分类预测
  • docker入门加实战—部署Java和前端项目
  • Flutter的Invalid use of a private type in a public API警告
  • 【数据结构】模拟实现LinkedList
  • STM32基于HAL库RT-Thread Demo测试
  • Kotlin Compose Multiplatform 跨平台开发实践之加入 iOS 支持
  • 女冰队长于柏巍,拒绝被年龄定义
  • 涉嫌严重违纪违法,57岁证监会副主席王建军被查
  • 王受文已任中华全国工商业联合会领导班子成员
  • 马克思主义理论研究教学名师系列访谈|杜玉华:马克思主义是“认识世界”和“改变世界”的思维工具
  • 中国武术协会原主席张耀庭逝世,曾促成电影《少林寺》拍摄
  • 江西德安回应“义门陈遗址建筑被没收”:将交由规范的义门陈相关社会组织管理