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. 时间获取_Date\SimpleDateFormat\Calendar类

     1.获取当前的日期,并把这个日期转换为指定格式的字符串,如2088-08-08 08:08:08 import java.text.SimpleDateFormat; import java.uti ...

  2. svn冲突问题详解 SVN版本冲突解决详解

    svn冲突问题详解 SVN版本冲突解决详解 (摘自西西软件园,原文链接http://www.cr173.com/html/46224_1.html) 解决版本冲突的命令.在冲突解决之后,需要使用svn ...

  3. kaggle Titanic

    # coding: utf-8 # In[19]: # 0.78468 # In[20]: import numpy as np import pandas as pd import warnings ...

  4. Ubuntu学习小结(一) 基础知识,系统安装,软件安装,解压缩

    这段时间,抽空研究了一下Ubuntu,虽然也有过到目前为止使用计算机最作死的经历,但目前已经学会了一些最基本的操作.在这里简单的记录一下,算是吸取的教训,供其他人借鉴. 1.装Ubuntu系统.装Ub ...

  5. C#之Socket断线重连

    一.网上常用方法 1.当Socket.Conneted == false时,调用如下函数进行判断 /// /// 当socket.connected为false时,进一步确定下当前连接状态 /// / ...

  6. Cookies的两种存取方式

    我们在使用webview开发时,少不了和cookie打交道,在网页端我这使用的是asp.net开发的,安卓下的cookie和windows平台下还是有些不同的,后来看了看,原来有两种cookie的存取 ...

  7. VB.NET提取TXT文档指定内容

    今天有浏览论坛时,又看见一篇是读取TXT文本文件的论题.Insus.NET也想以自己的想法来实现,并分享于此. 文本文件是比较复杂,获取数据也是一些文本行中取其中一部分.为了能够取到较精准的数据,In ...

  8. Git解决pull无法操作成功

    https://blog.csdn.net/chenjunfengf/article/details/78301957 场景 在git pull的时候,如果本地代码有改动,而服务器上代码也已经被其他人 ...

  9. Git分支管理命令

    1. 创建新分支 1)创建新仓库 git init git add README.md git commit -m "readme.md" git remote add origi ...

  10. ThinkPHP CURD 操作

    Thinkphp CURD操作php中实例还对象即可操作 (目录) 1.Add 1 调式程序 3 调出显示页面Trace信息 3 Dump 的含义 4 2.数据库查询 4 1.直接使用字符串进行查找 ...