Middle
What types of expectations are there in UI autotests? What is the difference between explicit and implicit?
sobes.tech AI
Answer from AI
In UI automation tests, there are two main types of waits: explicit waits and implicit waits.
-
Implicit waits are set once for the driver and apply to all element search operations. If an element is not immediately found, WebDriver will retry for the specified amount of time. This is convenient for simple cases but not always efficient, as the wait applies to all elements without exception.
-
Explicit waits allow you to specify wait conditions for a particular element or state. For example, waiting until an element becomes visible, clickable, or appears on the page. This is a more flexible and precise way to manage synchronization.
Differences:
| Criterion | Implicit waits | Explicit waits |
|---|---|---|
| Scope of action | Globally for all elements | Locally for a specific condition |
| Flexibility | Less | More, can wait for different conditions |
| Management | Set once | Set in each specific case |
Example of an explicit wait in Python with Selenium:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'submit-button')))
element.click()