等待元素出现之后再消失,界面上的loading icon都属于这种类型,之前的方法总是卡死,换这种方法目前还好用的

/**
* Check if the element present with customized timeout
* @param driver
* @param locator
* @param errorMessage
* @return
*/
public Boolean waitUntilElementPresent(WebDriver driver,final By locator, long timeOutInSeconds) {
Boolean isPresent = false;
for(int i=0;i<timeOutInSeconds;i++){
isPresent=SeleniumUtil.isElementPresent(driver,locator);
if(true==isPresent){
break;
}
else{
SeleniumUtil.sleep(1);
System.out.println("Wait no more than "+timeOutInSeconds+"s for loading icon display, wait "+(i+1)+"s");
}
}
return isPresent;
}
/**
* Wait until the element not present with customized timeout
* @param driver
* @param locator
* @param errorMessage
* @return
*/
public Boolean waitUntilElementNotPresent(WebDriver driver,final By locator, long timeOutInSeconds) {
Boolean isPresent = true;
for(int i=0;i<timeOutInSeconds;i++){
isPresent=SeleniumUtil.isElementPresent(driver,locator);
if(false==isPresent){
break;
}
else{
SeleniumUtil.sleep(1);
System.out.println("Wait no more than "+timeOutInSeconds+"s for loading icon disappear, wait "+(i+1)+"s");
}
}
return isPresent;
}
public void waitForLoadingDoneInNewWebPage(WebDriver driver){
By locator=By.cssSelector("div.x-mask-msg");
Boolean isPresent = this.waitUntilElementPresent(driver, locator, 10);
if(true==isPresent){
System.out.println("Loading icon display in new web page");
System.out.println("Wait for loading icon disappear in new web page");
Boolean stillPresent = this.waitUntilElementNotPresent(driver, locator, 120);
if(false==stillPresent){
System.out.println("Loading icon disappear in new web page.");
}
}
else{
System.out.println("Loading icon does'nt display in new web page.");
}
}

[Selenium]等待元素出现之后再消失,界面上的loading icon都属于这种类型,之前的方法总是卡死,换这种方法目前还好用的的更多相关文章

  1. [Selenium]怎样等待元素出现之后再消失,譬如Loading icon

    界面上有些元素是要先等它出现,再等它消失,譬如loading icon 这个是等多个loading icon出现后消失 /** * Wait for loading icon disappear in ...

  2. selenium 等待元素加载

    今天,尝试用代码指定自动化测试用例. 将测试record导出为C# 代码后,使用FF的drive ,发现执行一直失败,提示无法加载元素.顿时一种无力感袭来啊.还是硬着头皮找方法.尝试id name x ...

  3. 【亲测显式等待】Selenium:元素等待的4种方法

    Selenium:元素等待的4种方法 1.使用Thread.sleep(),这是最笨的方法,但有时候也能用到而且很实用.   2.隐式等待,隐性等待是指当要查找元素,而这个元素没有马上出现时,告诉We ...

  4. python selenium等待特定网页元素加载完毕

    selenium等待特定元素加载完毕 is_disappeared = WebDriverWait(driver, 8, 0.5, ignored_exceptions=TimeoutExceptio ...

  5. selenium等待机制学习笔记

    转载至: https://blog.csdn.net/huilan_same/article/details/52544521 1. 强制等待 第一种也是最简单粗暴的一种办法就是强制等待sleep(x ...

  6. Selenium定位元素

    Commands (命令) Action对当前状态进行操作失败时,停止测试 Assertion校验是否有产生正确的值 Element Locators指定HTML中的某元素 Patterns用于模式匹 ...

  7. selenium界面元素定位

    一.        Selenium界面元素定位 本文元素定位以das2为例 #导入包 from selenium import  webdriver #打开火狐驱动 driver=webdriver ...

  8. 强制等待&隐士等待&显示等待&元素定位方法封装

    前言 问题 学习selenium的同学估计大多数都遇见过一个问题 明明页面已经精准的定位到了元素,但是执行脚本的时候却经常报错没找到元素.其实原因很简单,就是脚本执行的速度很快,而浏览器加载页面的时候 ...

  9. python+selenium遇到元素定位不到的问题,顺便记录一下自己这次的错误(报错selenium.common.exceptions.NoSuchElementException)

    今天在写selenium一个发送邮件脚本时,遇到一些没有找到页面元素的错误.经过自己反复调试,找原因百度,终于解决了.简单总结一下吧,原因有以下几点: 一:Frame控件嵌套,.Frame/Ifram ...

随机推荐

  1. 《DSP using MATLAB》Problem 2.18

    1.代码: function [y, H] = conv_tp(h, x) % Linear Convolution using Toeplitz Matrix % ----------------- ...

  2. ringojs java jar 集成使用

    ringojs 可以方便进行java 代码的集成,我们可以把下载的jar包放到classpath,后者ringojs 的lib 目录 也可以进行代码编写 测试代码 集成了java 的一个hashid ...

  3. conan c&&c++ 包管理工具使用

    测试使用的是JFrog Artifactory CE 进行的私有包管理,具体的安装可以参考相关文档 启动JFrog Artifactory CE 使用docker docker run -d -p 8 ...

  4. ORA-01033: ORACLE initialization or shutdown in progress --手动删除表空间 DBF 后无法登陆问题

    进入CMD,执行set ORACLE_SID=fbms,确保连接到正确的SID: 2.执行sqlplus "/as sysdba" SQL>shutdown immediat ...

  5. 遍历树节点(多层)的方法(java)

    前序遍历,后序遍历,广度遍历,深度遍历,遍历一级节点.以及按钮如何响应点击事件. import java.awt.*; import java.awt.event.*; import java.uti ...

  6. 使用 Lombok 简化项目中无谓的Java代码

    在写使用Java时,难免会有一些模板代码要写,不然get/set,toString, hashCode, close 资源,定义构造函数等等.代码会显得很冗余,很长.Lombok项目可以是我们摆脱这些 ...

  7. charles手机抓包配置-1

    1.下载和安装Charles 下载和安装Charles软件.安装前要先安装Java运行环境,因为Charles是Java写的. 自己百度云上有破解版 2.安装电脑的Charles证书,对证书进行信任设 ...

  8. php error_log记录日志的使用方法和配置 (日志目录一定要手动创建)

    对于PHP开发者来 说,一旦某个产品投入使用,应该立即将 display_errors选项关闭,以免因为这些错误所透露的路径.数据库连接.数据表等信息而遭到黑客攻击.但是,任何一个产品在投入使用后,都 ...

  9. POJ 2777-题解

    一.题意 给你一排N个格子,M种颜色,P个操作.有两种操作:(1)C A B D:把[A, B]区间内的所有格子涂成颜色D.(2)P A B:输出[A, B]区间内的颜色的种类数.注意,初始颜色为1. ...

  10. solr跨core查询

    参考文档:这里的跨core不使用solrcloud http://wiki.apache.org/solr/CoreAdmin 注意:跨core查询功能相比单core查询,是有限制的   只需要在ur ...