1
我有一个下拉菜单,下面的html代码:我需要在下拉菜单项聚集成一个Python列表
<div class="dropdown open">
<button aria-expanded="true" class="btn btn-default btn-block dropdown-toggle" type="button" id="menu3" data-toggle="dropdown">
<span class="btn-chevron"></span>
<span class="btn-label" id="assign_product_selection">Select Product</span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu3">
<li role="presentation"><a role="menuitem" onclick="select_assignreadingproduct("Product One", 76997)">Product One</a></li>
<li role="presentation"><a role="menuitem" onclick="select_assignreadingproduct("Product Three", 76997)">Product Three</a></li>
<li role="presentation"><a role="menuitem" onclick="select_assignreadingproduct("Product Two", 76997)">Product Two</a></li>
</ul>
</div>
我试图让在下降中的所有项目的值下拉菜单:即(件产品,产品二,产品分类三),并把它们放入一个Python列表。这是我目前的,但它只是返回一个空的产品名称列表。
product_menu = driver.find_element_by_id('menu3')
product_options = product_menu.find_elements_by_xpath("//*[@role = 'menuitem']")
list_of_product_names = []
if len(product_options) < 1:
print 'no products listed'
else:
for item in product_options:
val_item = item.text
list_of_product_names.append(val_item)
print 'list of product names',list_of_product_names
我的输出:
产品名称[U '',U '',U '',U '',U '',U '',U '',U名单'',U '', U '' U '',U '',U '',U '',U '',U '',U '',U '',U '',U” ” U '' U '',U '', U '' U '',U '',U '',U '']
因为这不是一个真正的下拉列表中,'SELECT'元素,你有没有尝试过点击下拉菜单,以便'OPTIONS'是可见的? – JeffC
工作表示感谢! –
太棒了。我将我的评论转到了答案。请给予好评,如果你发现它有用(以及任何其他的答案是有用的),并把它标记为接受这样的问题被标记为回答。 – JeffC