等待元素出现之后再消失,界面上的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. Java中String.valueOf()方法的解释

    1. 由 基本数据型态转换成 String String 类别中已经提供了将基本数据型态转换成 String 的 static 方法 也就是 String.valueOf() 这个参数多载的方法 有下 ...

  2. Hive之 数据类型

    hive 目前支持的数据类型如下: -- 数值类型 Numeric TypesTINYINT (1-byte signed integer, from -128 to 127)SMALLINT (2- ...

  3. CentOS 6.5下安装Oracle 11g(转)

    最近开始学习CentOS使用,做些记录. 参考文献:Cent OS 6_5(x86_64)下安装Oracle 11g 一.硬件要求 1.内存&swap Minimum:1 GB of RAM ...

  4. PHP向客户端广播信息

    在网络中数据传播分为:Unicast(单播) , Multicast(多播或者组播) 和 Broadcast(广播).广播和多播仅应用于UDP,它们对需将报文同时传往多个接收者的应用来说十分重要.而 ...

  5. C++和C# WebService相互调用

    C#调用C++ gSOAP: 调用http://blog.csdn.net/ggz631047367/article/details/44567411的服务http://127.0.0.1:8089/ ...

  6. 【POJ】2778 DNA Sequence(AC自动机+矩阵快速幂)

    题目 传送门:QWQ 分析 对着Trie图搞快速幂. 为什么这样是对的呢? 详见:http://www.matrix67.com/blog/archives/276 有些地方还不是很理解......为 ...

  7. solr搜索之搜索精度问题我已经尽力了!!!

    solr搞了好久了,没啥进展,没啥大的突破,但是我真的尽力了! solr7可能是把默认搜索方式去掉了,如下: 在solr7里找了半天以及各种查资料也没发现这个默认搜索方式,后来想,可能是被edisma ...

  8. python打造漏洞补丁缺少检测

    前言: 当我们进行后渗透的时候,进行提权的时候 要识别被未打补丁的漏洞.来进行提权,从而 拿到管理员权限. 思路: 1.让使用者在cmd中打systeminfo命令.将补丁号 放入一个txt. 2.与 ...

  9. 2.spring整合ehcache 注解实现查询缓存,并实现实时缓存更新或删除

    转自:http://www.importnew.com/23358.html 写在前面:上一篇博客写了spring cache和ehcache的基本介绍,个人建议先把这些最基本的知识了解了才能对今天主 ...

  10. Spring IO Platform介绍

    为什么要用Spring IO Platform 今天无意间看到了一个关键词:"Spring IO Platform",第一直觉是不是有关于IO方面的框架或者包呢,查了一下,居然是为 ...