臨海大經(jīng)建設(shè)集團網(wǎng)站網(wǎng)站怎么做
app爬蟲中的Airtest元素存在或等待
一. poco等待
等待無錯誤
等待元素10秒。如果它沒有出現(xiàn),則不會引發(fā)任何錯誤。
poco('xxx').wait(timeout=10)
您還可以在.wait()之后執(zhí)行一些操作,如click或long_click
poco('xxx').wait(timeout=10).click()
poco('xxx').wait(timeout=10).long_click()
等待錯誤
等待元素10秒。如果元素未出現(xiàn),將引發(fā)PocoTargetTimeout錯誤。
poco('xxx').wait_for_appearance(20)
poco('xxx').wait_for_disappearance(20) # wait for disappearance of the element
常見的使用:
from poco.exceptions import PocoTargetTimeouttry:poco('xxx').wait_for_appearance(20)
except PocoTargetTimeout:# logging...# raise ...
等待元素(沒有時間設(shè)置)
Wait_for_all()將等待所有元素出現(xiàn)。Wait_for_any()將等待,直到任何一個元素出現(xiàn)。
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來告訴你元素的當(dāng)前狀態(tài)(不會引發(fā)錯誤)。
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)