最近在使用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. hunter-冲刺合集

    冲刺合集 一·项目相关 作业相关 具体描述 所属班级 2019秋福大软件工程实践Z班 作业要求 团队作业第五次-项目冲刺 作业正文 hunter--冲刺集合 团队名称 hunter小组 作业目标 最终 ...

  2. ros脚本断点调试-编写过程可以把过程变量输出到log查看的方法

    /caps-man registration-table :do {:foreach i in=[find interface~"5G"] do={:log info messag ...

  3. VS一个奇怪的发布问题

    同事的环境,发布项目时一直提示找不到某dll,在引用及bin里未发现黄色感叹号,后来发现问题是因为项目文件不小心包含了一个外部bin目录,并且该bin目录中的dll删除导致的.

  4. 2019-11-29-WPF-开启-ScrollViewer-的触摸滚动

    原文:2019-11-29-WPF-开启-ScrollViewer-的触摸滚动 title author date CreateTime categories WPF 开启 ScrollViewer ...

  5. node、npm、gulp安装

    1.先安装node.js ,官网下载地址:https://nodejs.org/en/ 2.安装完node之后,npm自动就安装了.可以直接在visual studio code 通过命令查看 nod ...

  6. C#配置文件configSections详解

    一.问题需求: 在项目中经常遇到需要写配置文件地方,目的就是不想在程序中关于一些信息写死,发布的时候只需要修改一下配置文件就可以,不需要每次都修改程序,如项目名称.数据库连接字符串.IP端口之类 的: ...

  7. C# vb .NET读取识别条形码线性条码gs1128

    gs1-128,ean-128是比较常见的条形码编码规则类型的一种.如何在C#,vb等.NET平台语言里实现快速准确读取该类型条形码呢?答案是使用SharpBarcode! SharpBarcode是 ...

  8. 史上最全的音视频SDK包分享给大家

    史上最全的音视频SDK包分享给大家 概述一下SDK功能: 项目 详情视频通信  支持多种分辨率的视频通信语音通信  提供语音通信,可支持高清宽带语音动态创建房间  可以根据需要,随时创建房间H5 支持 ...

  9. C#字符串(String)类型中@的用法

    C# string 字符串的前面可以加 @(称作"逐字字符串")将转义字符(\)当作普通字符对待,比如: string str = @"C:\Windows"; ...

  10. Delphi - Delphi7 调用阿里大于实现短信消息验证

    阿里大于是阿里通信旗下产品,融合了三大运营商的通信能力,提供包括短信.语音.流量直充.私密专线.店铺手机号等个性化服务.每条四分五,价钱还算公道,经老农测试,响应速度非常快,基本上是秒到.官方文档提供 ...