示例:等待
<select id="myselect"></select>
填充
<option value="123">One-two-three</option>
我怎样才能用Python做到这一点?
答案 0 :(得分:4)
您可以使用presence_of_element_located
和explicit 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