WebDriver-Python-下拉菜单中有多少个元素 [英] WebDriver - Python - How many elements in a drop-down menu

查看:166
本文介绍了WebDriver-Python-下拉菜单中有多少个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试计算一个下拉菜单中有多少个元素.我的部分代码是:

i try to count how many element have a drop-down menu. Part of my code is :

while a < ? :

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

    a += 1

其他选项是通过索引检查元素是否存在,但是我无法找到解决方案.

Other option is to check by index if element exists, but i'm not able to found the solution.

推荐答案

使用

options

返回属于此选择标记的所有选项的列表

Returns a list of all options belonging to this select tag

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

这篇关于WebDriver-Python-下拉菜单中有多少个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆