Kent
0
Q:

python selenium explicit wait

How many types of waits do you know in Selenium?
  There are 3 types of wait I use
    1- =Implicit Wait=
  - Implicit wait is triggered when driver is not able to find web element.
  - Driver will wait for the given time or until it finds the element.
  - If driver does not find web element, it will throw NoSuchElementException.

   2- =Explicit Wait=
- I use it when I want to wait for specific conditions or 
  specific web elements. 
    - Such as: elementIsClickable
    - elementIsDisplayed
    - titleIs...
       - To be able to use explicit wait:
       - You need to create instance of WebDriverWait class.
      WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
      wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a/h3")));
  
3- Thread.sleep
	I avoid to use it since it makes my test heavier and slower
0
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "myDynamicElement"))
    )
finally:
    driver.quit()
2
val = 20 # in seconds
driver.implicitly_wait(val)
-1

New to Communities?

Join the community