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”来控制整个下拉框不可见.这个时候如果直接操 ...
随机推荐
- final 子类禁止重写
<?php //子类中编写和父类中完全一样的函数,是对父类中的函数进行重写 class BaseClass{ public function test() { echo "BaseCl ...
- 100851K King’s Inspection
传送门 题目大意 给你一张图,求这张图的汉密尔顿回路. 分析 因为m≤n+20,所以如果存在回路一定是在一个环中加入了至多20条边.我们先考虑dfs,但我们发现如果出现图1这种情况就会是复杂度爆炸 图 ...
- JavaWeb_泛型(Generic)
JDK5以前,对象保存到集合中就会失去其特性,取出时通常要程序员手工进行类型的强制转换,这样不可避免的就会引发程序的一些安全性问题.例如: ArrayList list = new ArrayList ...
- 《Maven实战》笔记-7-持续集成
一.持续集成的步骤: 1.持续编译 2.持续数据库集成 3.持续测试 4.持续审查 5.持续部署 6.持续反馈 二.持续集成工具——Hudson 1.安装Hudson 2.准备Subversion ...
- leetcode Word Search 待解决?
终于搞定了这个DFS,最近这个DFS写的很不顺手,我一直以为递归这种东西只是在解重构时比较麻烦,现在看来,连最简单的返回true和false的逻辑关系都不能说one hundred present 搞 ...
- 2019年第十届蓝桥杯省赛-糖果(一维状压dp)
看到20的数据量很容易想到状压dp. 开1<<20大小的数组来记录状态,枚举n个糖包,将其放入不同状态中(类似01背包思想) 时间复杂度O(n*(2^20)). import java.u ...
- Charles抓包https请求
平时使用Charles抓包,http的请求一眼就看到具体的请求信息返回信息等,但是如果是https请求,则是出现<unknow>,如下图: 若想要抓取https请求,怎么办呢? 1.连接C ...
- [raspberry pi3] opensuse使用splash中问题处理
问题一: QXcbConnection: Could not connect to display :1594410864 解决方案: export QT_QPA_PLATFORM=offscreen
- jQuery实例代码-表单相关
select option 获取选中项的文本值 $("#ddl_GoOutReasonType option:selected").text() 根据索引定于option项 $(& ...
- 抽象类(abstract class)和接口(Interface)的区别
前言 抽象类(abstract class)和接口(Interface)是Java语言中对于抽象类定义进行支持的两种机制,赋予了Java强大的面向对象能力. 二者具有很大的相似性,甚至可以相互替换,因 ...