selenium之python源码解读-expected_conditions
一、expected_conditions
之前在 selenium之python源码解读-WebDriverWait 中说到,until方法中method参数,需要传入一个function对象,如果每次都自定义或者使用lambda函数,显得比较麻烦。
其实在expected_conditions中,Selenium提供了一些常用的元素查找的条件类
在selenium\webdriver\support\expected_conditions.py中定义的所有类如下:
class title_contains(object):
class presence_of_element_located(object):
class visibility_of_element_located(object):
class visibility_of(object):
class presence_of_all_elements_located(object):
class visibility_of_any_elements_located(object):
class visibility_of_all_elements_located(object):
class text_to_be_present_in_element(object):
class text_to_be_present_in_element_value(object):
class frame_to_be_available_and_switch_to_it(object):
class invisibility_of_element_located(object):
class element_to_be_clickable(object):
class staleness_of(object):
class element_to_be_selected(object):
class element_located_to_be_selected(object):
class element_selection_state_to_be(object):
class element_located_selection_state_to_be(object):
class number_of_windows_to_be(object):
class new_window_is_opened(object):
class alert_is_present(object):
在上面定义的类中都实现了 __call__(self, driver)方法,这就意味着该类的对象是一个可调用的对象
如以visibility_of_element_located类为例:
实例化一个对象:visibility_of_element_located(locator)
在对象后加():调用对象,即调用类的 __call__方法,visibility_of_element_located(locator)(driver)
二、类中的 __init__ 和__call__方法传参总结
1、传入locator,和driver参数
def __init__(self, locator):
self.locator = locator def __call__(self, driver):
return _find_element(driver, self.locator)
而locator,需要传入一个iterateble对象,如tuple,(by.ID,"id")
def _find_element(driver, by):
"""Looks up an element. Logs and re-raises ``WebDriverException``
if thrown."""
try:
return driver.find_element(*by)
except NoSuchElementException as e:
raise e
except WebDriverException as e:
raise e
2、传入element,和ignored参数
def __init__(self, element):
self.element = element def __call__(self, ignored):
return _element_if_visible(self.element)
该类型的传参有4个
class visibility_of(object) class staleness_of(object) class element_located_to_be_selected(object) class element_selection_state_to_be(object)
lement_located_to_be_selected(object)和element_selection_state_to_be(object)实现的功能是一样的 3、其他还有title、window、handler、alert此处不再一一例举,具体查看源码
selenium之python源码解读-expected_conditions的更多相关文章
- selenium之python源码解读-webdriver继承关系
一.webdriver继承关系 在selenium中,无论是常用的Firefox Driver 还是Chrome Driver和Ie Drive,他们都继承至selenium\webdriver\re ...
- selenium之python源码解读-WebDriverWait
一.显示等待 所谓显示等待,是针对某一个特定的元素设置等待时间,如果在规定的时间内找到了该元素,就执行相关的操作,如果在规定的时间内没有找到该元素,在抛出异常 PS:注意显示等待和隐身等待的区别,隐身 ...
- 如何判断一个Http Message的结束——python源码解读
HTTP/1.1 默认的连接方式是长连接,不能通过简单的TCP连接关闭判断HttpMessage的结束. 以下是几种判断HttpMessage结束的方式: 1. HTTP协议约定status ...
- python 源码解读2
http://www.jianshu.com/users/4d4a2f26740b/latest_articles http://blog.csdn.net/ssjhust123/article/ca ...
- Apache Beam WordCount编程实战及源码解读
概述:Apache Beam WordCount编程实战及源码解读,并通过intellij IDEA和terminal两种方式调试运行WordCount程序,Apache Beam对大数据的批处理和流 ...
- 基于Docker的TensorFlow机器学习框架搭建和实例源码解读
概述:基于Docker的TensorFlow机器学习框架搭建和实例源码解读,TensorFlow作为最火热的机器学习框架之一,Docker是的容器,可以很好的结合起来,为机器学习或者科研人员提供便捷的 ...
- Spark学习之路 (十六)SparkCore的源码解读(二)spark-submit提交脚本
一.概述 上一篇主要是介绍了spark启动的一些脚本,这篇主要分析一下Spark源码中提交任务脚本的处理逻辑,从spark-submit一步步深入进去看看任务提交的整体流程,首先看一下整体的流程概要图 ...
- ansible源码解读
Ansible源码获取 Ansible Github:https://github.com/ansible Ansible目录结构 $ tree -L 2 ansible-2.0.0.0 ansibl ...
- DRF(1) - REST、DRF(View源码解读、APIView源码解读)
一.REST 1.什么是编程? 数据结构和算法的结合. 2.什么是REST? 首先回顾我们曾经做过的图书管理系统,我们是这样设计url的,如下: /books/ /get_all_books/ 访问所 ...
随机推荐
- js判断是Android还是iOS
var u = navigator.userAgent, app = navigator.appVersion; var isAndroid = u.indexOf('Android') > - ...
- [转帖]鲁大师Q3季度PC内存排行:DDR3彻底淘汰 DDR5要来了
鲁大师Q3季度PC内存排行:DDR3彻底淘汰 DDR5要来了 https://www.cnbeta.com/articles/tech/902347.htm 10月23日消息,今天鲁大师公布Q3季度P ...
- Redis string操作命令
字符串类型 string set 从v2.6.12版本开始,Redis增强了set功能, 语法如下: SET key value [EX seconds] [PX milliseconds] [NX ...
- python离线安装外部库(第三方库)
在官网下好外部库,解压后,点击解压后的文件夹,按住shift 右击在命令行中执行 输入 python setup.py install
- 18 COUNTIF函数
求大于小于等于某个数字的数字有多少 格式:=COUNTIF(数据区,"条件") 注意条件需要用英文双引号引起来. 举个例子: =COUNTIF(A2:D5,">20 ...
- CH02基于ZYNQ的嵌入式LINUX移植
CH02基于ZYNQ的嵌入式LINUX移植 1.1概述 实验环境: Windows 10 专业版 Vmware workstation 14.1.1 Ubuntu 16.04.3 Xilinx SDx ...
- Stack Overflow是如何做应用缓存的
首先要说下缓存是什么?缓存,就是在取出数据结果后,暂时将数据存储在某些可以快速存取的位置(例如各种NoSQL如Redis,HBase,又或MemoryCache等等),于是就可以让这些耗时的数据结果多 ...
- python入门-windows下anaconda环境搭建
1. anaconda下载 根据根据自己系统下载32位还是64位,还有版本 python3.6——64bit python3.6——32bit python2.7——64bit python2.7—— ...
- 爬虫相关--requests库
requests的理想:HTTP for Humans 一.八个方法 相比较urllib模块,requests模块要简单很多,但是需要单独安装: 在windows系统下只需要在命令行输入命令 pip ...
- 关于Echarts柱状图点击事件的实现方法
开发过程中,我们经常会碰到这样的需求:在柱状图上,点击某条柱形,调用相应的方法或跳转相应的界面 接下来就详细介绍如何实现柱状图的点击事件,其中maChart是绘图对象 一.简单的点击事件 myChar ...