简体   繁体   中英

How to find length of drop-down with mat-options with Selenium Webdriver with Python?

I am dealing with drop-downs that were created with Angular JS. When I look at HTML, the drop-down options that I see have a tag and not a standard . So when I try to figure out the drop-down length, the following standard approach doesn't work

 select = drowser.find_element_by_id(elementID))
 print len(select.options)

How else can I try to find out how many options my drop-down has?

EDITED: Below is an example of HTML:

在此处输入图片说明

Your element is not a HTML select tag and it's not possible to use Selenium's Select class on it. Instead get all elements with tag mat-option under div.mat-select-content :

 selectOptions = drowser.find_elements_by_css_selector("div.mat-select-content mat-option")
 print len(selectOptions)

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