selenium处理页面select元素
selenium为网页中选择框元素的获取特别引入了一个Select对象,
引入对象的方式:
from selenium.webdriver.support.ui import Select
查询文档可以知道 Select 所支持的方法:
class selenium.webdriver.support.select.Select(webelement)[source]
Constructor. A check is made that the given element is, indeed, a SELECT tag. If it is not, then an UnexpectedTagNameException is thrown. Args :
webelement - element SELECT element to wrap
Example:
from selenium.webdriver.support.ui import Select # 引入 Select(driver.find_element_by_tag_name(“select”)).select_by_index() # 获取select元素 all_selected_options[source]
Returns a list of all selected options belonging to this select tag deselect_all()[source]
Clear all selected entries. This is only valid when the SELECT supports multiple selections. throws NotImplementedError If the SELECT does not support multiple selections deselect_by_index(index)[source]
Deselect the option at the given index. This is done by examing the “index” attribute of an element, and not merely by counting. Args :
index - The option at this index will be deselected
throws NoSuchElementException If there is no option with specisied index in SELECT deselect_by_value(value)[source]
Deselect all options that have a value matching the argument. That is, when given “foo” this would deselect an option like: <option value=”foo”>Bar</option>
Args :
value - The value to match against
throws NoSuchElementException If there is no option with specisied value in SELECT deselect_by_visible_text(text)[source]
Deselect all options that display text matching the argument. That is, when given “Bar” this would deselect an option like: <option value=”foo”>Bar</option> Args :
text - The visible text to match against
first_selected_option[source]
The first selected option in this select tag (or the currently selected option in a normal select) options[source]
Returns a list of all options belonging to this select tag select_by_index(index)[source]
Select the option at the given index. This is done by examing the “index” attribute of an element, and not merely by counting. Args :
index - The option at this index will be selected
throws NoSuchElementException If there is no option with specisied index in SELECT select_by_value(value)[source]
Select all options that have a value matching the argument. That is, when given “foo” this would select an option like: <option value=”foo”>Bar</option> Args :
value - The value to match against
throws NoSuchElementException If there is no option with specisied value in SELECT select_by_visible_text(text)[source]
Select all options that display text matching the argument. That is, when given “Bar” this would select an option like: <option value=”foo”>Bar</option>
Args :
text - The visible text to match against
throws NoSuchElementException If there is no option with specisied text in SELECT
selenium处理页面select元素的更多相关文章
- Selenium获取页面指定元素个数
测试需求: 获取页面中下拉框个数,并验证是否与预期个数一致 方法1:因下拉框的tagname属性值为select,可通过获取标签为select的元素来获取下拉框个数 List<WebElem ...
- selenium 滑动页面至元素可见
滚动页面 在自动化操作中,如果web页面过长,而我们需要的元素并不在当前可视页面中,那么selenium就无法对其进行操作:此时,我们就需要像平时操作浏览器一样来滚动页面,使我们需要操作的对象可见! ...
- Selenium操作页面元素
转自:http://blog.sina.com.cn/s/blog_6966650401012a7q.html 一.输入框(text field or textarea) //找到输入框元素: Web ...
- 利用PIL和Selenium实现页面元素截图
预备 照张相片 selenium.webdriver可以实现对显示页面的截图: from selenium import webdriver dr = webdriver.Firefox() dr.g ...
- 【selenium学习笔记一】python + selenium定位页面元素的办法。
1.什么是Selenium,为什么web测试,大家都用它? Selenium设计初衷就是为web项目的验收测试再开发.内核使用的是javaScript语言编写,几乎支持所以能运行javaScript的 ...
- python + selenium定位页面元素的办法
1.什么是Selenium,为什么web测试,大家都用它? Selenium设计初衷就是为web项目的验收测试再开发.内核使用的是javaScript语言编写,几乎支持所以能运行javaScript的 ...
- selenium操作隐藏的元素
有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: Python 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操 ...
- js操作:selenium无法操作隐藏元素问题
对于前端隐藏元素,一直是selenium自动化定位元素的隐形杀手,脚本跑到隐藏元素时位置时报各种各样的错误, 隐藏的下拉菜单又没有办法避免,此帖只为交流隐藏元素自动化定位处理方法(3种操作) ...
- selenium操作隐藏的元素 (下拉框类型)
有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: Python 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操 ...
随机推荐
- CodeForces 1109C. Sasha and a Patient Friend
题目简述:维护以下三种操作 1. "1 t s":在时刻$t$插入命令$s$.保证任意操作后,任意时刻至多只有一个命令. 2. "2 t":删除时刻$t$的命令 ...
- SQl Server Tsql基本编程 ,循环语句 ,存储过程
一些比较重要但是不一定经常用的 句子 Tsql定义变量 declare @a int : 定义的变量前面必须用@,数据类型是SQL里的数据类型,执行的时候要把需要的有关联的代码一起执行,单独执行一条 ...
- WarTransportation TopCoder - 8404
传送门 分析 我们高兴的发现数据范围特别小,所以我们可以随便搞.因为一共只砍掉一条路,所以我们先算出对于任意一个点如果将它的出边割掉一条则它到达终点的最坏情况的最短距离是多少,然后我们从终点向起点反着 ...
- Ubuntu jdk安装详细
安装jdk步骤: 1.首先连接130的ip地址,进去Tools拷贝jdk压缩文件(Tools中已经有下载好的jdk版本,也可自己另行下载) 2.将拷贝好的压缩文件解压 tar -zxvf 压缩文件名 ...
- 问题:org.hibernate.LazyInitializationException: failed to lazily initialize
今天搞了一上午,都在解决这个问题:org.hibernate.LazyInitializationException: failed to lazily initialize 原因很简单,是在非法的s ...
- javaScript实现轮播图
一.需求分析 在首页完成对轮播图的效果实现,完成自动切换图片的功能. 二.技术分析 获取元素 document.getElementById(“id 名称”) 事件(onload) 定时操作: set ...
- Cactus在jexus上安装
在成功安装完Mono和jexus后(强烈建议Mono 4.2.1以上,jexus 5.6.1 以上,本人测试环境就是Mono 4.2.1和jexus 5.6.1) 第一步: 先配置jexus安装目录下 ...
- C 语言 clock() 函数,例:计算多项式值
C 语言 clock() 函数,例:计算多项式值 /** * clock(): 捕捉从程序开始运行到 clock() 被调用时所耗费的时间. * 这个时间单位是 clock tick, 即" ...
- [WIP]React 核心概念
创建: 2019/05/01 Hello World ReactDOM.render( <p>sample</p>, document.getElementById('ro ...
- SnackBar使用
注意:build(BuildContext context)在 Scaffold.of(context)之前时,会报错,解决办法:通过build widget来解决,如下代码. import 'pac ...