robot framework Selenium2library wait小问题
最近在使用selenium2Library时,用到其中的 Wait Until Page函数,因我们的网页相对比较敏感,经常获取不到,不明觉历
看看源码吧,如下:
def wait_until_page_contains_element(self, locator, timeout=None, error=None):
"""Waits until element specified with `locator` appears on current page. Fails if `timeout` expires before the element appears. See
`introduction` for more information about `timeout` and its
default value. `error` can be used to override the default error message. See also `Wait Until Page Contains`, `Wait For Condition`,
`Wait Until Element Is Visible` and BuiltIn keyword `Wait Until
Keyword Succeeds`.
"""
if not error:
error = "Element '%s' did not appear in <TIMEOUT>" % locator
self._wait_until(timeout, error, self._is_element_present, locator)
核心的等待函数在这里
def _wait_until_no_error(self, timeout, wait_func, *args):
timeout = robot.utils.timestr_to_secs(timeout) if timeout is not None else self._timeout_in_secs
maxtime = time.time() + timeout
while True:
timeout_error = wait_func(*args)
if not timeout_error: return
if time.time() > maxtime:
raise AssertionError(timeout_error)
time.sleep(0.2)
。。。。
函数中,写死等待0.2秒,还没有参数可以改。太暴力。
再来看看selenium原生的webdriverWait是怎么写的
def until(self, method, message=''):
"""Calls the method provided with the driver as an argument until the \
return value is not False."""
screen = None
stacktrace = None end_time = time.time() + self._timeout
while True:
try:
value = method(self._driver)
if value:
return value
except self._ignored_exceptions as exc:
screen = getattr(exc, 'screen', None)
stacktrace = getattr(exc, 'stacktrace', None)
time.sleep(self._poll)
if time.time() > end_time:
break
raise TimeoutException(message, screen, stacktrace)
从源码中可以看出,等待时间可以自定义,except除了元素不可见,也还可以加自定义的错误。比selenium2library更好用
robot framework Selenium2library wait小问题的更多相关文章
- Robot Framework + Selenium2Library环境下,结合Selenium Grid实施分布式自动化测试
最近一段时间,公司在推行自动化测试流程,本人有幸参与了自定义通用控件的关键字封装和脚本辅助编写.数据驱动管理.测试用例执行管理等一系列工具软件的研发工作,积累了一些经验,在此与大家做一下分享,也算是做 ...
- Robot Framework selenium2library 常用关键字
Selenium Library SeleniumLibrary is a Robot Framework test library that uses the popular Selenium we ...
- robot framework selenium2library定位
进行页面元素操作,最麻烦的莫过于元素定位了,经常提示element is not visible 或者element is not exist 下面介绍常见的定位方法和定位中的问题 1 使用name和 ...
- Robot Framework自动化测试环境准备(一)
Robot framework是诺西(NSN)开源的一套自动化测试工具,在通信设备自动化测试中很实用,它基于Python开发,主要模拟NMS网管配置数据到网元NODE,并读取配置看配置是否生效. == ...
- Robot Framework 使用笔记
条件表达式: Run Keyword If 表达式 执行动作 ... ELSE IF 表达式 执行动作 ... ELSE 执行动作 基础格式见上表,下面是我遇到的坑: 表达式:判断字符串变量是 ...
- Robot Framework自动化_Selenium2Library 关键字
Robot Framework自动化_Selenium2Library 关键字 培训老师:肖能尤 2016/06/12 课程目的 一.Robot framework Selenium2Library ...
- python3+Robot Framework+PyCharm自动化测试框架设计
关于自动化测试框架的设计,笔者在前面的随笔里面有介绍和总结,这里结合实际的项目例子做个demo,环境部署参考笔者的的随笔<python3+Robot Framework+PyCharm环境部署及 ...
- Robot Framework + Selenium2Lib
Robot Framework + Selenium2Lib 最近一段时间,公司在推行自动化测试流程,本人有幸参与了自定义通用控件的关键字封装和脚本辅助编写.数据驱动管理.测试用例执行管理等一系列工具 ...
- Robot Framework使用Phantomjs进行无界面UI自动化测试
Robot Framework 是一款关键字驱动的验收自动化测试框架,现在在国内使用的越来越广泛了.一种通用的Web UI自动化测试解决方案是Robot Framework+Selenium2Libr ...
随机推荐
- php脚本l导出mysq的blob格式数据-hex和unhex的用法
前言 之前我们介绍过使用PHP脚本导出sql语句到测试服中的流程和注意点, 之前有个问题还没有解决的,就是mysql中blob类型数据是导不成功的. 这次找到了解决方法,这里记录一下. 什么是blob ...
- Visual Studio 调试系列7 查看变量占用的内存(使用内存窗口)
系列目录 [已更新最新开发文章,点击查看详细] 在调试期间,“内存”窗口显示应用程序正在使用的内存空间. 调试器窗口(如监视窗口.自动窗口.局部变量窗口和快速监视对话框)显示变量,这些变量存储 ...
- 目标检测 <二> TensorFlow安装
一:创建TensorFlow工作环境目录 1. 在anconda安装目录下找到envs目录然后进入 2. 在当前目录下创建一个文件夹改名为tensorflow 二: 创建TensorFlow工作环境 ...
- layui.dropdown.js
前 在 layui 框架下做了一个小组件,是下拉框功能,当然也可以很好的变成其他组件,前提你会修改. 还需要更多的完善.后期(我也不清楚会是啥时候会优化)
- python 做词云图
#导入需要模块 import jieba import numpy as np import matplotlib.pyplot as plt from PIL import Image from w ...
- 如何防止短信API接口遍历
短信API接口在web中得到越来越多的应用,如用户注册,登录,密码重置等业务模块都会使用手机验证码进行身份验证.一般情况下,我们会采用这样的安全策略,将短信发送频率限制在正常的业务流控范围内,比如,一 ...
- 【学习笔记】字符串—马拉车(Manacher)
[学习笔记]字符串-马拉车(Manacher) 一:[前言] 马拉车用于求解连续回文子串问题,效率极高. 其核心思想与 \(kmp\) 类似:继承. --引自 \(yyx\) 学姐 二:[算法原理] ...
- Java面试-TCP连接及其优化
作为一个后端程序员,网络连接这块是一个绕不过的砍,当你在做服务器优化的时候,网络优化也是其中一环,那么作为网络连接中最基础的部分-TCP连接你了解吗?今天我们来仔细看看这个部分. TCP建立连接-三次 ...
- service的yaml说明
apiVersion: v1 kind: Service metadata: name: nginx-service labels: app: nginx spec: ports: - port: 8 ...
- table中td文字超出长度用省略号隐藏超出内容,鼠标点击内容全部显示
1,设置css样式 <style>table {width: 100%;float: left;table-layout:fixed;width:600px;border:1px soli ...