webdriver学习笔记-类方法属性||四(2)下拉框(select类)的三种处理用法
发布日期:2022-03-03 10:44:17 浏览次数:2 分类:技术文章

本文共 632 字,大约阅读时间需要 2 分钟。

一、知识点

1、select下拉框的三种处理和用法

(1)按索引index的方法定位下拉框

nr = driver.find_element_by_id('nr')   #元素定位到下拉框

select = Select(nr)   #select()是类需要实例化,Select(self,webelement)

select.select_by_index(0)  #按索引选择下拉框的内容

(2)按value值的方法定位下拉框

select.select_by_value('你好呀')

(3)按text文本值的方法定位下拉框

select.select_by_visible_text('python语言')

二、实例

打开网页-下拉框中有(报名号和身份证号),选择下拉框内容

from selenium import webdriverfrom selenium.webdriver.support.select import Selectimport time as t#select类下拉框的操作driver = webdriver.Chrome()driver.get('xxxxxxx')nr = driver.find_element_by_id('ksLoginUsername')select = Select(nr)  #select()是类需要实例化,Select(self,webdriver)select.select_by_index(1)

 

转载地址:https://blog.csdn.net/yangjiepo/article/details/117884987 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:webdriver学习笔记||三(1)浏览器属性-窗口切换
下一篇:webdriver学习笔记||三、浏览器的属性-方法

发表评论

最新留言

很好
[***.229.124.182]2024年03月30日 05时59分59秒