[Airtest]4.Elements exist or wait

A. poco wait

wait without error

wait for elements for 10 seconds. If it's not appeared, there won't be any error raised.

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

and you can follow some operations after .wait(), like click or long_click

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

wait with error

wait for elements for 10 seconds. If the element isn't appeared, PocoTargetTimeout error will be raised.

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

common use:

from poco.exceptions import PocoTargetTimeout

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

wait for elements(no time setting)

wait_for_all() wil wait until all the elements appeared. wait_for_any() will wait until any one of the elements appeared.

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

check if exist without wait

poco('xxx').exists() will return True or False to tell you the current state of the elements(no error will be raised).

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

B. 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)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容