Selenium: How to wait for options in a select to be populated?

后端 未结 9 1802
温柔的废话
温柔的废话 2020-12-14 18:14

I am using Selenium for the first time and am overwhelmed by the options. I am using the IDE in Firefox.

When my page loads, it subsequently fetches values via an JS

9条回答
  •  我在风中等你
    2020-12-14 18:42

    Try the below code

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.common.exceptions import TimeoutException
    
    try:
        # 10 is the maximum time to wait
        element = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.CSS_SELECTOR, "#mySelectId option[value='valueofOptionYouExpectToBeLoaded']"))
        )
    except TimeoutException:
        print("Time out")
    
    #  Write your code
    

提交回复
热议问题