這取決於你還在等什麼。
下面是一個例子,以等待與while
和_is_visible
功能在網頁上出現的元素,以檢查是否在頁面上存在的元素:
class DockerContainerDeployer(object):
self.browser = webdriver.Firefox()
def deploy(self)
# actions...
# wait until the docker container is deployed
# by checking a div that give us the status
while not self._is_visible("#cluster-status .deployed"):
# you can add an implicity wait to check it every 10s with
# self.browser.implicitly_wait(10)
pass
# docker container deployed
def _is_visible(self, locator, timeout = 2):
"""
Check if an element is visible
"""
try:
ui.WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((By.CSS_SELECTOR, locator)))
return True
except TimeoutException:
return False
你能有點什麼你更清晰想要實現? – Abhinav
我想讓它繼續運行/循環代碼 – T2T
如果你想要解決一個特定的條件,可以使用'while',或者如果你想迭代特定次數,使用'for '中的_1。 –
Abhinav