Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 375
jhh Phi Avatar asked Oct 28 '25 05:10

jhh Phi


1 Answers

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
like image 71
Vinícius Figueiredo Avatar answered Oct 30 '25 22:10

Vinícius Figueiredo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!