前言
wait_until等待某個條件為真才繼續往下執行。默認的超時時間為10s,每0.5查詢一次,這倆參數選填。可以設置超時時間和輪詢間隔。
可以作為添加后校驗元素是否存在的場景
入參介紹
def wait_until(condition_fn, timeout_secs=10, interval_secs=0.5):
"""
:param condition_fn: A function taking no arguments that represents the \
condition to be waited for.
:param timeout_secs: The timeout, in seconds, after which the condition is \
deemed to have failed.
:param interval_secs: The interval, in seconds, at which the condition \
function is polled to determine whether the wait has succeeded.
Waits until the given condition function evaluates to true. This is most
commonly used to wait for an element to exist::
wait_until(Text("Finished!").exists)
More elaborate conditions are also possible using Python lambda
expressions. For instance, to wait until a text no longer exists::
wait_until(lambda: not Text("Uploading...").exists())
``wait_until`` raises
:py:class:`selenium.common.exceptions.TimeoutException` if the condition is
not satisfied within the given number of seconds. The parameter
``interval_secs`` specifies the number of seconds Helium waits between
evaluating the condition function.
"""
_get_api_impl().wait_until_impl(condition_fn, timeout_secs, interval_secs)
舉例說明
wait_until(Text("Finished!").exists) # 等待直到給定的條件函數評估為true。 這是最通常用於等待元素存在,失敗后直接報錯
wait_until(lambda: not Text("Uploading...").exists()) # 例如,等待直到文本不再存在
歡迎關注