Selenium Python如何等待select中的选项被填充?

时间:2017-07-17 01:44:48

标签: python selenium web-scraping

示例:等待

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

填充

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

我怎样才能用Python做到这一点?

1 个答案:

答案 0 :(得分:4)

您可以使用presence_of_element_locatedexplicit waiting找到带有css选择器的元素:

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