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元素的更多相关文章

  1. Selenium获取页面指定元素个数

    测试需求: 获取页面中下拉框个数,并验证是否与预期个数一致 方法1:因下拉框的tagname属性值为select,可通过获取标签为select的元素来获取下拉框个数   List<WebElem ...

  2. selenium 滑动页面至元素可见

    滚动页面 在自动化操作中,如果web页面过长,而我们需要的元素并不在当前可视页面中,那么selenium就无法对其进行操作:此时,我们就需要像平时操作浏览器一样来滚动页面,使我们需要操作的对象可见! ...

  3. Selenium操作页面元素

    转自:http://blog.sina.com.cn/s/blog_6966650401012a7q.html 一.输入框(text field or textarea) //找到输入框元素: Web ...

  4. 利用PIL和Selenium实现页面元素截图

    预备 照张相片 selenium.webdriver可以实现对显示页面的截图: from selenium import webdriver dr = webdriver.Firefox() dr.g ...

  5. 【selenium学习笔记一】python + selenium定位页面元素的办法。

    1.什么是Selenium,为什么web测试,大家都用它? Selenium设计初衷就是为web项目的验收测试再开发.内核使用的是javaScript语言编写,几乎支持所以能运行javaScript的 ...

  6. python + selenium定位页面元素的办法

    1.什么是Selenium,为什么web测试,大家都用它? Selenium设计初衷就是为web项目的验收测试再开发.内核使用的是javaScript语言编写,几乎支持所以能运行javaScript的 ...

  7. selenium操作隐藏的元素

    有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: Python 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操 ...

  8. js操作:selenium无法操作隐藏元素问题

    对于前端隐藏元素,一直是selenium自动化定位元素的隐形杀手,脚本跑到隐藏元素时位置时报各种各样的错误, 隐藏的下拉菜单又没有办法避免,此帖只为交流隐藏元素自动化定位处理方法(3种操作)      ...

  9. selenium操作隐藏的元素 (下拉框类型)

    有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了.例如,下面的情况: Python 页面主要通过“display:none”来控制整个下拉框不可见.这个时候如果直接操 ...

随机推荐

  1. Codeforces 464E The Classic Problem (最短路 + 主席树 + hash)

    题意及思路 这个题加深了我对主席树的理解,是个好题.每次更新某个点的距离时,是以之前对这个点的插入操作形成的线段树为基础,在O(logn)的时间中造出了一颗新的线段树,相比直接创建n颗线段树更省时间. ...

  2. JavaScript toLowerCase() 方法

    定义和用法 toLowerCase() 方法用于把字符串转换为小写. 语法 stringObject.toLowerCase() 返回值 一个新的字符串,在其中 stringObject 的所有大写字 ...

  3. gearman client的doBackground 与doNormal方法的区别

    doNormal方法是阻塞的,需要等到worker处理完之后才返回,否则一直阻塞住; doBackground 方法是非阻塞的,只要将数据发送到gearmand之后,就立马返回,不等待worker的处 ...

  4. linux sdcv命令

    一.简介 sdcv全称为stardict console version,是终端下的词典.   二.安装 1)安装sdcv yum install -y sdcv 2)安装字典 http://www. ...

  5. HUST高级软件工程--测试管理工具实践--Day4

    测试管理工具实践--Day4 今天完成任务情况: 小靳 今天,主要在前两天的基础上继续学习挖掘jira相关内容: 学会了如何创建项目,并且创建了issue 学会了创建一般账号,并且可以将任务分发给一般 ...

  6. 关于IO流---笔记1

    今日内容介绍1.File2.递归=================================================================================1 I ...

  7. C++面试笔记--排序

    这里我们开始复习排序的一些面试题. 首先我们来看一下各个排序方法的时间复杂度和稳定性的比较,见下面表格: 排序法 平均时间 最差情形 稳定度 额外空间 备注 冒泡 O(n2)     O(n2) 稳定 ...

  8. Comparator 排序

    例1: import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import ja ...

  9. SQLServer存储引擎——04.数据

    4. SQL SERVER存储引擎之数据篇 (4.1)文件 (0)主数据文件.mdf初始文件大小至少为3MB,次要数据文件.ndf初始大小,同日志文件一样至少为512KB: (1)SQL SERVER ...

  10. 使用sphinx快速生成Python API 文档

    一  简单介绍 不管是开源还是闭源,文档都是很重要的.当然理论上说,最好的文档就是代码本身,但是要让所有人都能读懂你的代码这太难了.所以我们要写文档.大部分情况,我们不希望维护一份代码再加上一份文档, ...