简体   繁体   中英

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. 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())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM