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)
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大数据采集及分析RPA

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值