2014-12-13 56 views
0

我試着去統計有多少元素有一個下拉菜單。我的部分代碼是:WebDriver - Python - 下拉菜單中有多少個元素

while a < ? : 

    Select(driver.find_element_by_id("MyBox")).select_by_index(a) 

    a += 1 

其他選項是通過索引檢查元素是否存在,但我無法找到解決方案。

回答

1

使用.options屬性:

options

返回屬於這個選擇標籤

select = Select(driver.find_element_by_id("MyBox")) 
print(len(select.options)) 
+0

謝謝你的所有選項列表!我會嘗試它 – Marco 2014-12-13 11:23:47

+0

它完美的作品!非常感謝你@alecxe – Marco 2014-12-13 11:42:19