**
python-下拉框常见定位方法总结
**
UI自动化时经常会遇到页面上有下拉框需要定位的问题,今天就在这里给大家分享一下定位select下拉框的经验。
一般情况下,我们在页面上通过Chrome开发工具查看到的有三类下拉框:
1、常见的 select option格式 下拉框
一般步骤为:先定位select这个大元素,再具体定位各个option选项,当要选中下拉框中的某一选项时,可选择通过for循环查找定位再点击,也可以通过xpath直接定位到需要的选项再点击,也就是下面的代码:
select = driver.find_element_by_name("testname") # 这里可选select框的常见属性id、name、class等
options = select.find_elements_by_tag_name("testname")
for option in options:
print "Value is: " + option.get_attribute("value")
print "Text is:" +option.text
if 'testname' in option.text: # 这里使用