【Python+selenium Wendriver API】之下拉框定位
上代码:
# coding:utf-8
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
import time driver = webdriver.Chrome()
driver.get("https://www.baidu.com/")
driver.implicitly_wait(20) mouse = driver.find_element_by_link_text("设置")
ActionChains(driver).move_to_element(mouse).perform()
driver.find_element_by_link_text("搜索设置").click()
time.sleep(2)
# 实例化select
s = Select(driver.find_element_by_id("nr"))
# 定位选项
s.select_by_value("") # 选择value="20"的项:通过value属性
time.sleep(2) #为了明显的看出变化
s.select_by_index(0) # 选择第一项选项:通过选项的顺序选择,第一个为 0
time.sleep(2) #为了明显的看出变化
s.select_by_visible_text("每页显示50条") # 选择text="每页显示50条"的值,即在下拉时我们可以看到的文本
Select提供了三种选择方法:
select_by_index(index) ——通过选项的顺序,第一个为 0
select_by_value(value) ——通过value属性
select_by_visible_text(text) ——通过选项可见文本Select提供了四种方法取消选择:
deselect_by_index(index)
deselect_by_value(value)
deselect_by_visible_text(text)
deselect_all()Select提供了三个属性方法提供信息:
options ——提供所有的选项的列表,其中都是选项的WebElement元素
all_selected_options ——提供所有被选中的选项的列表,其中也均为选项的WebElement元素
first_selected_option ——提供第一个被选中的选项,也是下拉框的默认值通过Select提供的方法和属性,我们可以对标准select下拉框进行任何操作,但是对于非select标签的伪下拉框,需要使用XPath定位;
其他文章:
https://blog.csdn.net/zwq912318834/article/details/79197114
https://www.cnblogs.com/fengyiru6369/p/7088836.html
【Python+selenium Wendriver API】之下拉框定位的更多相关文章
- 转:python webdriver API 之下拉框处理
下拉框也是 web 页面上非常常见的功能,webdriver 对于一般的下拉框处理起来也相当简单,要想定位下拉框中的内容,首先需要定位到下拉框:这样的二次定位,我们在前面的例子中已经有过使用,下面通过 ...
- 【Python+selenium Wendriver API】之操作警告和弹出框
参考文章: <Python+Selenium笔记(九):操作警告和弹出框>
- python+selenium七:下拉框、选项框、select用法
# from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsimpo ...
- selenium自学笔记---下拉框定位元素select
下拉框1.先定位select 然后在定位option city = driver.find_element_by_id("selCities_0") city.find_eleme ...
- Python+Selenium操作select下拉框
首先需要倒入Select模块: from selenium.webdriver.support.select import Select 常用方法: 通过索引定位:select_by_index() ...
- 【Python+selenium Wendriver API】之鼠标悬停事件
# encoding=utf-8 from selenium import webdriver from selenium.webdriver.common.action_chains import ...
- Python自动化之下拉框,隐藏标签定位 代码&报错解决
python自动化:下拉框定位方法之select标签 style="display: none;" 报错 selenium.common.exceptions.ElementNo ...
- WEB自动化(Python+selenium)的API
在做Web自动化过程中,汇总了Python+selenium的API相关方法,给公司里的同事做了第二次培训,分享给大家 ...
- 《手把手教你》系列技巧篇(三十二)-java+ selenium自动化测试-select 下拉框(详解教程)
1.简介 在实际自动化测试过程中,我们也避免不了会遇到下拉选择的测试,因此宏哥在这里直接分享和介绍一下,希望小伙伴或者童鞋们在以后工作中遇到可以有所帮助. 2.select 下拉框 2.1Select ...
随机推荐
- POJ 2914 Minimum Cut (全局最小割)
[题目链接] http://poj.org/problem?id=2914 [题目大意] 求出一个最小边割集,使得图不连通 [题解] 利用stoerwagner算法直接求出全局最小割,即答案. [代码 ...
- IE8兼容性问题
由于业务的需要,我们竟然还要支持IE8,听着就让人很心酸呀.不过在进行适配的过程中,会发现还是有一定规律的,基本上帮相关问题改了,页面也就能正常显示了.下面就总结下对IE8适配过程中所进行的修改. 1 ...
- Ubuntu 16.04出现:dpkg: 处理软件包 xxx (--configure)时出错:
如下所示: 解决方法: #将info文件夹更名 sudo mv /var/lib/dpkg/info /var/lib/dpkg/info_old #再新建一个新的info文件夹 sudo mkdir ...
- EF执行存储工程报错 String[4]: Size 属性具有无效大小值 0。
EF中执行存储过程报错 String[4]: Size 属性具有无效大小值 0 排查后是如下问题所致,给定的参数没有设定大小(加入红框内的就可以了) private string GetCode(MC ...
- C#的多线程——使用async和await来完成异步编程(Asynchronous Programming with async and await)
https://msdn.microsoft.com/zh-cn/library/mt674882.aspx 侵删 更新于:2015年6月20日 欲获得最新的Visual Studio 2017 RC ...
- cocurrent包ExecutorService线程池
16. 执行器服务 ExecutorService java.util.concurrent.ExecutorService 接口表示一个异步执行机制,使我们能够在后台执行任务.因此一个 Execut ...
- UIWebView to view self signed websites (No private api, not NSURLConnection) - is it possible?
What it actually does is to intercept the UIWebView to launch a NSURLConnection to allow the server ...
- 【Hadoop】Flink VS Spark?Drill VS Presto?
参考资料: drill 官网:http://drill.apache.org/ drill安装使用:https://segmentfault.com/a/1190000002652348 drill简 ...
- oracle分页sql模板
select t2.* from (select t1.*,rownum rn from (select * from mytest) t1 where rownum<=860010) t2 w ...
- 【LeetCode-面试算法经典-Java实现】【109-Convert Sorted List to Binary Search Tree(排序链表转换成二叉排序树)】
[109-Convert Sorted List to Binary Search Tree(排序链表转换成二叉排序树)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 ...