等待元素出现之后再消失,界面上的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. Dijkstra算法(C语言)

    Dijkstra算法 1.定义概览 Dijkstra(迪杰斯特拉)算法是典型的单源最短路径算法,用于计算一个节点到其他所有节点的最短路径.主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止.Di ...

  2. 《DSP using MATLAB》Problem 2.18

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

  3. Testng优势

    选择Testng的理由: 1.可指定执行顺序, dependsOnMethods 属性来应对测试的依赖性问题. 2.·参数化1:轻轻松松从XML中得到参数 @BeforeClass public vo ...

  4. celery docker 基本使用

    项目参考官网资料,比较简单的add task 具体代码参考https://github.com/rongfengliang/celery-docker-demo 项目结构 ├── README.md ...

  5. 机器学习 ----Tensorflow

    机器学习笔记4-Tensorflow线性模型示例及TensorBoard的使用 机器学习笔记3-Tensorflow简介 机器学习笔记2 – sklearn之iris数据集 机器学习笔记1 - Hel ...

  6. 修改numa和io调度优化mysql性能

    一.NUMA设置单机单实例,建议关闭NUMA,关闭的方法有三种:1.硬件层,在BIOS中设置关闭:2.OS内核,启动时设置numa=off:3.可以用numactl命令将内存分配策略修改为interl ...

  7. SQL中利用脚本创建database mail.

    SQL中利用脚本创建database mail   编写人:CC阿爸 2014-6-14 多话不讲,请参考以下脚本 use  

  8. hBuilder培训资源视频教程汇总

    DCloud对开发者的学习支持分3个层面:官方文档.三方专业培训.网友经验分享 DCloud的精力主要在做产品,配套的文档也会一直完善好.但专业的培训还不是DCloud能做好的,在HTML5中国产业联 ...

  9. js复制URL链接

    html: <div style="height:0px; text-indent:-10000px;"><span id="hdcopyurl&quo ...

  10. SPM——How to use github

    In this semester, we take a class called 'Software Project Management'. And in this class, we have l ...