我正在处理的项目将下拉列表从简单更改为ul li。在此之前从下拉列表中删除所有选项,我将执行以下操作:
myList = []
el = browser.find_element_by_id('Filter_ClientDistrict')
for option in el.find_elements_by_tag_name('option'):
myList.append(option.get_attribute("value"))
如果现在的代码如下所示,如何从同一下拉列表中删除所有选项:
答案 0 :(得分:2)
应该是
browser.find_element_by_css_selector('#Filter_ClientDistrict button.dropdown-toggle').click()
WebDriverWait(browser, 5).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#Filter_ClientDistrict ul li"))
myList = []
el = browser.find_element_by_id('Filter_ClientDistrict')
for option in el.find_elements_by_css_selector('ul li'):
myList.append(option.get_attribute("innerText").strip())