Python + WebDriver: Explicit vs Implicit Waits

Selenium Webdriver provides two types of waits – implicit & explicit. An explicit wait makes WebDriver to wait for a certain condition to occur before proceeding further with executions. An implicit wait makes WebDriver to poll the DOM for a certain amount of time when trying to locate an element.
Full information

### Explicit Waits ###
”’
An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. The worst case of this is time.sleep(), which sets the condition to an exact time period to wait. There are some convenience methods provided that help you write code that will wait only as long as required. WebDriverWait in combination with ExpectedCondition is one way this can be accomplished.
from selenium.webdriver.support import expected_conditions as EC
”’
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID,’someid’)))

### Implicit Waits ###
”’
An implicit wait is to tell WebDriver to pool the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.
”’
from selenium import webdriver
driver = webdriver.Firefox()
driver.implicitly_wait(10) # seconds
driver.get(“http://somedomain/url_that_delays_loading”)
myDynamicElement = driver.find_element_by_id(“myDynamicElement”)

Comments

Popular posts from this blog

Robot Framework vs Cucumber

Performance Testing of RESTful APIs Using JMeter

Verification displayed number of rows inside table by Robot Framework