首页 > 其他 > 详细

Selenium定位下拉选

时间:2019-10-08 18:16:35      阅读:67      评论:0      收藏:0      [点我收藏+]

技术分享图片

Selenium定位下拉选有三种写法,如下:

#引入Select
from selenium.webdriver.support.ui import Select
# 通过index进行选择,从1开始
Select(driver.find_element_by_name("priority")).select_by_index(1)
# 通过value进行选择
Select(driver.find_element_by_name("priority")).select_by_value("中")
# 通过选项文字进行选择
Select(driver.find_element_by_name("priority")).select_by_visible_text("普通")

#选择下拉选
select = driver.find_element_by_name("priority")
# 获取select里面的option标签,注意使用find_elements
options_list = select.find_elements_by_tag_name(‘option‘)
# 遍历option
for option in options_list:
#获取下拉框的value和text
  print ("Value is:%s Text is:%s" %(option.get_attribute("value"),option.text))

#输入检索式选择框
# 先定位输入框输入关键字
driver.find_element_by_id(‘id‘).send_keys(‘紧急‘)
# 然后定位ul
ul = driver.find_element_by_css_selector(".ui-autocomplete-items")
# 最后定位里面所有值
li = ul.find_elements_by_tag_name(‘li‘)
# 选取想要的值
li[0].click() # 0代表选择第一个值

参考:https://www.jianshu.com/p/9c459b9cc5a9

 

 

Selenium定位下拉选

原文:https://www.cnblogs.com/yanding/p/11636826.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!