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)

你可能感兴趣的:(爬虫)