selenium基础(下拉菜单操作)
selenium基础(下拉菜单操作)
非select/option元素:
1.触发下拉列表出现
2.等待下拉列表中的元素出现,然后进行选择元素即可。
select/option元素:
下拉框操作-Select类
selenium提供Select类来处理select/option
1.引入
from selenium.webdriver.support.ui import Select
2.创建Select对象,传入元素
ele = driver.find_element_by_xpath(元素定位表达式)
s = Select(ele)
3.选择下拉列表值:
s.select_by_value(value值) #通过value
s.select_by_index(index) #通过下标
s.select_by_visible_text(文本') #通过文本
例:百度设置-高级搜索-下拉框
from selenium import webdriver
from selenium.webdriver.support.ui import Select#select类,下拉菜单使用
from selenium.webdriver.support.wait import WebDriverWait#等待时间包,在限定时间内查找元素
from selenium.webdriver.common.action_chains import ActionChains#鼠标操作包
from selenium.webdriver.common.keys import Keys#键盘操作包
import time#时间包
import unittest#单元测试包 driver=webdriver.Firefox()
driver.get('https://www.baidu.com')
above=driver.find_element_by_link_text('设置')#找到“设置”按钮
ActionChains(driver).move_to_element(above).perform()#将鼠标放置到“设置”按钮上
WebDriverWait(driver,10).until(lambda a:a.find_element_by_link_text('高级搜索'))#10秒钟之内找到元素
driver.find_element_by_link_text('高级搜索').click()
time.sleep(3)
#找到下拉框并找到要选择的元素
Select(driver.find_element_by_name('ft')).select_by_value('pdf')#通过value进行定位
time.sleep(3)
ele=driver.find_element_by_name('ft')
s=Select(ele)
s.select_by_index(6)#通过下标进行定位
time.sleep(3)
s.select_by_visible_text('微软 Word (.doc)')#通过文本内容进行查找
time.sleep(2)
driver.quit()
selenium基础(下拉菜单操作)的更多相关文章
- selenium,unittest——下拉菜单操作,百度账号设置修改
#encoding=utf-8from selenium import webdriverimport time,unittest, re,sysfrom HTMLTestRunner import ...
- selenium.common.exceptions.ElementNotVisibleException: Message: element not visible处理方法:selenium针对下拉菜单事件的处理
使用Selenium爬虫时,可能会遇到一些下拉菜单,动态加载,如果直接使用find_element_by_函数会报错,显示selenium.common.exceptions.ElementNotVi ...
- selenium定位下拉菜单好文
http://www.cnblogs.com/nbkhic/archive/2011/10/23/2221726.html 定位下拉菜单
- [Selenium] 针对下拉菜单出现之后又立马消失的问题,通过Javascript改变元素的可见属性
public void clickDateDropDownButton() { SeleniumUtil.jsClick(driver, page.getDateDropdownButtonOfInv ...
- html基础 下拉菜单和文本域的基本操作
结构代码 所在城市: <select > <option selected>北京</option> <option>上海</option> ...
- 『心善渊』Selenium3.0基础 — 13、Selenium操作下拉菜单
目录 1.使用Selenium中的Select类来处理下拉菜单(推荐) 2.下拉菜单对象的其他操作(了解) 3.通过元素二次定位方式操作下拉菜单(重点) (1)了解元素二次定位 (2)示例: 页面中的 ...
- Selenium下拉菜单(Select)的操作-----Selenium快速入门(五)
对于一般元素的操作,我们只要掌握本系列的第二,三章即可大致足够.对于下拉菜单(Select)的操作,Selenium有专门的类Select进行处理.文档地址为:http://seleniumhq.gi ...
- selenium webdriver从安装到使用(python语言),显示等待和隐性等待用法,切换窗口或者frame,弹框处理,下拉菜单处理,模拟鼠标键盘操作等
selenium的用法 selenium2.0主要包含selenium IDE 和selenium webDriver,IDE有点类似QTP和LoadRunner的录制功能,就是firefox浏览器的 ...
- Python+Selenium笔记(八):操作下拉菜单
(一) Select类 Select类是selenium的一个特定的类,用来与下拉菜单和列表交互. 下拉菜单和列表是通过HTML的<select> 元素实现的.选择项是通过<sele ...
随机推荐
- POJ3241 最小曼哈顿距离生成树 - 真有趣哇
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门 原题目描述在最下面. 给你n个坐标, ...
- Spring源码由浅入深系列五 GetBean
获取bean的过程如上图所示.下一章将继续图示讲解createBean的过程.
- 完美解决 IE6 position:fixed 固定定位问题
关于 position:fixed; 属性 生成绝对定位的元素,相对于浏览器窗口进行定位. 元素的位置通过 “left”, “top”, “right” 以及 “bottom” 属性进行规定. pos ...
- <pygame> 打飞机(小游戏)
0.游戏的基本实现 ''' 游戏的基本实现 游戏的初始化:设置游戏窗口,绘制图像的初始位置,设定游戏时钟 游戏循环:设置刷新频率,检测用户交互,更新所有图像位置,更新屏幕显示 ''' 1.安装pyga ...
- 请求参数MD5加密---函数助手
- java 数组中的数值反转输出
package com.test; /** *数组元素反转 * */ public class ArraySwap { public static void main(String[] args) { ...
- SpringCloud学习笔记《---06 Config 分布式配置中心---》基础篇
- cpu子系统(优化)
如果业务已经在线上,你要优化,第一步如何做 首先进行服务器数据采集,和性能监测分析 一:使用cacti,nagios,zabbix 等监控工具 二:使用linux 自带的一些监控指令:vmstat,i ...
- python、Jupyter运行时间
1.Python time time()方法 import time time_start=time.time() time_end=time.time() print('totally cost', ...
- Elasticsearch.net一些开发笔记
.net下开发es半年多了,留下些笔记 //https://www.elastic.co/guide/cn/elasticsearch/guide/current/combining-filters. ...