[英]How to get all options from ul li drop-down using Selenium Webdriver with Python?
The project that I am working on changes drop-down lists from simple ones to ul li. 我正在处理的项目将下拉列表从简单列表更改为ul li。 Prior to this to scrap all options from a drop down list I would do the following: 在此之前,从下拉列表中删除所有选项,我将执行以下操作:
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"))
How can scrap all the options from the same drop down list if its code looks like this now: 如果现在代码看起来像这样,如何从相同的下拉列表中删除所有选项:
It should be 它应该是
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())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.