最近在使用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小问题的更多相关文章

  1. Robot Framework + Selenium2Library环境下,结合Selenium Grid实施分布式自动化测试

    最近一段时间,公司在推行自动化测试流程,本人有幸参与了自定义通用控件的关键字封装和脚本辅助编写.数据驱动管理.测试用例执行管理等一系列工具软件的研发工作,积累了一些经验,在此与大家做一下分享,也算是做 ...

  2. Robot Framework selenium2library 常用关键字

    Selenium Library SeleniumLibrary is a Robot Framework test library that uses the popular Selenium we ...

  3. robot framework selenium2library定位

    进行页面元素操作,最麻烦的莫过于元素定位了,经常提示element is not visible 或者element is not exist 下面介绍常见的定位方法和定位中的问题 1 使用name和 ...

  4. Robot Framework自动化测试环境准备(一)

    Robot framework是诺西(NSN)开源的一套自动化测试工具,在通信设备自动化测试中很实用,它基于Python开发,主要模拟NMS网管配置数据到网元NODE,并读取配置看配置是否生效. == ...

  5. Robot Framework 使用笔记

    条件表达式: Run Keyword If 表达式 执行动作   ... ELSE IF 表达式 执行动作 ... ELSE 执行动作   基础格式见上表,下面是我遇到的坑: 表达式:判断字符串变量是 ...

  6. Robot Framework自动化_Selenium2Library 关键字

    Robot Framework自动化_Selenium2Library 关键字 培训老师:肖能尤 2016/06/12 课程目的 一.Robot framework Selenium2Library ...

  7. python3+Robot Framework+PyCharm自动化测试框架设计

    关于自动化测试框架的设计,笔者在前面的随笔里面有介绍和总结,这里结合实际的项目例子做个demo,环境部署参考笔者的的随笔<python3+Robot Framework+PyCharm环境部署及 ...

  8. Robot Framework + Selenium2Lib

    Robot Framework + Selenium2Lib 最近一段时间,公司在推行自动化测试流程,本人有幸参与了自定义通用控件的关键字封装和脚本辅助编写.数据驱动管理.测试用例执行管理等一系列工具 ...

  9. Robot Framework使用Phantomjs进行无界面UI自动化测试

    Robot Framework 是一款关键字驱动的验收自动化测试框架,现在在国内使用的越来越广泛了.一种通用的Web UI自动化测试解决方案是Robot Framework+Selenium2Libr ...

随机推荐

  1. OpenCV像素操作和图形绘制

    像素操作 #include<iostream> #include<opencv2/opencv.hpp> using namespace std; using namespac ...

  2. EFCore代码实践

    参考:https://www.cnblogs.com/Wddpct/p/6835574.html 控制台程序依赖注入参考:https://www.cnblogs.com/Wddpct/p/721920 ...

  3. 记一次ssh.exec_command(cmd)执行后读取结果为空

    # 连接跳板机,执行插标签 def con_tmp_machine(mobile_phoneno, myguid): keyfile = os.path.expanduser('/Users/kusy ...

  4. ACM 常用 OJ 网址

    ACM 常用 OJ 网址 浙江大学: https://pintia.cn/ 北京大学: http://poj.org/ 杭州电子科技大学: http://acm.hdu.edu.cn/ 中国科技大学: ...

  5. scala基础题--函数可以没有返回值案例,编写一个函数,从终端输入一个整数,打印出对应的金字塔

    函数可以没有返回值案例,编写一个函数,从终端输入一个整数,打印出对应的金字塔 import scala.io.StdIn object work02 { def main(args: Array[St ...

  6. 使用Prometheus+Grafana监控JVM

    一.概述 JMX Exporter https://github.com/prometheus/jmx_exporter 它是Prometheus官方组件,作为一个JAVA Agent来提供本地JVM ...

  7. Redis(九)高可用专栏之Sentinel模式

    本文讲述Redis高可用方案中的哨兵模式--Sentinel,RedisClient中的Jedis如何使用以及使用原理. Redis主从复制 Redis Sentinel模式 Jedis中的Senti ...

  8. 2019-11-29-浅谈-Windows-桌面端触摸架构演进

    原文:2019-11-29-浅谈-Windows-桌面端触摸架构演进 title author date CreateTime categories 浅谈 Windows 桌面端触摸架构演进 lind ...

  9. 12、Render函数

    1.什么是Render函数 Vue 推荐在绝大多数情况下使用模板来创建你的 HTML.然而在一些场景中,你真的需要 JavaScript 的完全编程的能力.这时你可以用渲染函数,它比模板更接近编译器. ...

  10. 【开发笔记】- yml中出现特殊字符启动失败的问题

    问题描述: yml配置中出现特殊字符,启动时抛出异常: Caused by: org.yaml.snakeyaml.constructor.ConstructorException: Can't co ...