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”来控制整个下拉框不可见.这个时候如果直接操 ...
随机推荐
- GUI编程02
1 编写一个导航栏 from tkinter import * root = Tk() root.title("测试") root.geometry("400x400+4 ...
- CMake 默认编译、链接选项
查看cmake默认编译和链接的参数设置 CMakeLists.txt 文件内容: cmake_minimum_required(VERSION 3.2) message(STATUS "CM ...
- Entity Framework Tutorial Basics(33):Spatial Data type support in Entity Framework 5.0
Spatial Data type support in Entity Framework 5.0 MS SQL Server 2008 introduced two spatial data typ ...
- Entity Framework Tutorial Basics(6):Model Browser
Model Browser: We have created our first Entity Data Model for School database in the previous secti ...
- [学习笔记]_exit和exit深入理解
#include<stdio.h> #include<stdlib.h> #include<string.h> #include <unistd.h> ...
- [译]内联Javascript vs 外置Javascript
本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...
- c#百分比计算
//此方法得到的百分比后小数太多,不行double percent=Convert.ToDouble(2)/Convert.ToDouble(34); string result=(percent*1 ...
- .NET DataTable DataSet转json代码
/// <summary> /// dataTable转换成Json格式 /// </summary> /// <param name="dt"> ...
- javascript 字典类型的使用
javascript 字典类型的使用 1.使用Array: var arr = new Array(); arr["zs"] = "zhangsan"; ar ...
- 记一次成功部署kolla-ansible ocata版本过程
1.安装的docker版本 [root@controller ~]# docker --versionDocker version 17.09.1-ce, build 19e2cf6 2.安装的ans ...