How to use 'expected conditions' to check for an element in python-selenium?

后端 未结 5 1769
不思量自难忘°
不思量自难忘° 2021-01-12 16:59

I have trouble understanding how to use an \'expected conditions\' to check for the presence of an element. Given this documentation it is not clear at all how to use this.

5条回答
  •  灰色年华
    2021-01-12 17:17

    First you need to import expected_conditions module from selenium.webdriver.support. With this module you can check several conditions of the element with giving expected time as well

    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.Chrome()
    driver.get("http://domain/element")
    try:
        element = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, "idxxx"))
        )
    finally:
        driver.quit()
    

提交回复
热议问题