selenium show wait and implicit wait

Selenium has three ways to wait for elements:
1. Implicit wait:
driver.implicitly_wait(30)

Waiting for an element to be found, or a command to complete, an exception will be thrown if the set time is exceeded. This is a global variable, which is the longest execution time for each command executed by the Driver. It can also be understood as the timeout time

. 2. Display waiting:
from selenium.webdriver.support.ui import WebDriverWait

#WebDriverWait(driver, timeout, poll_frequency=0.5, ignored_exceptions=None)

wait = WebDriverWait(context.driver, 30)
is_disappeared = wait.until_not(lambda x:x.find_element(by=how, value=what).is_displayed())
element = wait.until(lambda x:x.find_elements_by_xpath(locatorString))


Explicitly wait until the appearance of an element or the clickable condition of an element, look for the element every poll_frequency=0.5 (default value), if you can't wait, just wait, unless it is all within the specified timeout. If it is not found, then an Exception will be thrown.

3. Thread waiting:
import time
time.sleep(2)


Notes: If implicit waiting and display waiting are set at the same time, the implicit waiting is the first priority, that is, if the implicit waiting time is greater than the display waiting, the display waiting time setting is invalid when the display waiting is executed, because If the driver cannot find the element, it will first wait for the implicit wait time.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326990575&siteId=291194637