jhh Phi
jhh Phi

Reputation: 159

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

Example: To wait for

<select id="myselect"></select>

to be populated with

<option value="123">One-two-three</option>

How can I do it in Python?

Upvotes: 4

Views: 6101

Answers (1)

Vin&#237;cius Figueiredo
Vin&#237;cius Figueiredo

Reputation: 6518

You can use presence_of_element_located and explicit waiting to locate the element with a css selector:

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:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, "option[value='123']"))
    )
    print("Option loaded")
except TimeoutException:
    print("Time exceeded!")

#  Do Your Stuff

Upvotes: 9

Related Questions