最近在使用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. centos7.5安装java JDK、tomcat、mysql

    参考资料: https://www.cnblogs.com/sxdcgaq8080/p/7492426.html https://blog.csdn.net/ds986619036/article/d ...

  2. RabbitMQ操作代码封装

    1.Message.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; u ...

  3. Qt对话框之二:模态、非模态、半模态对话框

    一.模态对话框 模态对话框:阻塞同一应用程序中其它可视窗口输入的对话框.模态对话框有自己的事件循环,用户必须完成这个对话框中的交互操作,并且关闭了它之后才能访问应用程序中的其它任何窗口. 显示模态对话 ...

  4. mybatis 的 dao 接口跟 xml 文件里面的 sql 是如何建立关系的?

    mybatis 会先解析这些xml 文件,通过 xml 文件里面的命名空间 (namespace)跟dao 建立关系:然后 xml 中的每段 sql 会有一个id 跟 dao 中的接口进行关联. 那么 ...

  5. 局域网Linux机器中病毒简单处理 .aliyun.sh 挖矿病毒 ---不彻底

    1. 昨天晚上同事打电话给我说自己的服务器上面的redis无故被清空了,并且查看aof 日志有很多 wget和write指令 一想就是大事不好.局域网中病毒了.. 2. 今天早上到公司忙完一阵简单看了 ...

  6. [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ'

    在Navicat Premium中执行Mysql的一条删除语句,虽然执行成功了,却提示已下错误: 受影响的行: 时间: .005s of ORDER BY clause is not in GROUP ...

  7. Qt 的两个许可证区别分析:LGPL 和商业协议

    Qt 的两个许可证区别分析:LGPL 和商业协议 Qt 有两个许可证:LGPL 和商业协议.这两个协议在现在的 Qt 版本中的代码是完全一致的(潜在含义是,Qt 的早期版本,商业版的 Qt 通常包含有 ...

  8. [转] linux 查找文本过滤grep正则表达式命令详解用法

    grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用 ...

  9. gentelella 开源后台使用记录

    前言 gentelella是一款开源后台,github地址是:https://github.com/ColorlibHQ/gentelella 使用 表单验证 parsley 验证 在form.htm ...

  10. golang-Json编码解码

    目录 一. 类型映射 二. 输出控制 三. 类型编码 四. 类型解码 五. 输出重写 六. 扩展功能 七. Bson编码 在线工具:https://www.json.cn 一. 类型映射 golang ...