Python Selenium下拉框问题:无法选择Wayne RESA (82)选项
解决方案
你遇到的问题根源是这个网站的ISD下拉框不是原生HTML <select> 元素,而是用自定义UI组件模拟的,所以Selenium的Select类无法识别和操作它。换用直接定位目标选项并点击的方式即可解决:
# 导入所需模块(确保已导入) from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # 等待下拉框可点击并点击展开选项列表 isd_dropdown = WebDriverWait(browser, 10).until( EC.element_to_be_clickable((By.ID, "isds")) ) isd_dropdown.click() # 等待目标选项可点击并执行选择 target_option = WebDriverWait(browser, 10).until( EC.element_to_be_clickable((By.XPATH, "//*[@data-value='119']")) ) target_option.click()
补充说明
- 优先使用
element_to_be_clickable而非visibility_of_element_located,确保元素处于可交互状态 - 如果
data-value定位失效,可改用文本精准定位:(By.XPATH, "//*[text()='Wayne RESA (82)']") - 无需使用
ActionChains的move_to_element,直接点击元素的逻辑更稳定
内容的提问来源于stack exchange,提问作者Victor
相关产品推荐
相关产品推荐

