Wait Mechanisms Flashcards
the tool has a built in time it is willing to wait for an action to occur.
If the expected action does not occur within that time frame, then the tool records a failure and it moves on
Which are the common limitations of the attempt to provide timing context to the automation?
- If the tool is set to wait 3 seconds, then an action that occurs in 3.0001 seconds—perhaps well within the contextual time range of the manual tester—will be considered a failure.
- If the automator removes all timing consideration, then it is possible that the tool will literally wait forever for an action to occur.
Why explicit wait mechanism should not be used in our automation?
This type of wait mechanism is always aimed at the worst possible case. Since the worst possible
case does not really occur that often, most of this time waiting is simply wasted. We get the risk that automation runs slower than a manual tester running exactly the same test.
two main types of waiting mechanisms in Selenium with WebDriver
- explicit waits
- implicit waits
How can we set up an implicit wait?
driver = webdriver.Chrome() #just after when the WebDriver object is first created. driver.implicitly_wait(10)
How the The implicit wait works?
- will be in effect until the WebDriver is destroyed
- instructs WebDriver to poll the DOM for a certain amount of time when trying to find an element which is not immediately found.
- If the element shows up within that time period, the script continues to run.
- The implicit wait will work for any element or elements that are defined in the script.
How the The explicit wait works?
It requires that the automator defines (usually for a specific element) exactly how long WebDriver should wait for that particular element, often for a particular state of that element.
explicit waits are easy to work with, since
include convenient methods which work with waits for specific expected conditions.
How can we code explicit conditions in Python?
WebDriverWait(), in conjunction with an ExpectedCondition.
CODE: Importing Explicit Wait Methods
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
CODE: How does it work the next code?
# Import Explicit Wait Methods then wait = WebDriverWait(driver, 10) element = wait.until(EC.element_to_be_clickable((By.ID, ‘someID’)))
wait up to 10 seconds, checking every 500 milliseconds, for an element to be identified by ID defined as ‘someid’. If the WebElement is not found after 10 seconds, the code will throw a TimeoutException. If the WebElement is found, a reference to it will be placed in the variable element and the code will continue.