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

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

[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模板导出PDF

    本次完善综合特点: 一对一,点对点的给对应的地方写值,比如模板里面放了个name标识,在程序里把“张三”赋给name,那么输出的pdf里面name的地方就变成了张三,准确方便快捷 支持中文,可以使用自 ...

  2. C-语言第二次作业(大一下)

    要求一.设计过程                                                       作业(1) 1.提交列表 6-7 删除字符串中数字字符 2.设计思路(6分 ...

  3. flow flow-typed 定义简单demo

    flow-typed 安装 全局 npm install -g flow-typed 测试代码 一个简单全局函数 目录根目录 flow-typed userLibDef.js declare func ...

  4. nats 学习 request/reply 模式基本使用

    nats 一个云原生的消息系统,使用简单,客户端丰富,支持的模式是pub/sub 但是集成比较灵活,可以支持loadblance, request/reply pub/sub 代码演示的是reques ...

  5. linux环境下git的安装配置

    1.查看git的最新版本: 查看最新版git:访问https://www.kernel.org/pub/software/scm/git/或者https://github.com/git/git/re ...

  6. Androoid studio 2.3 AAPT err(Facade for 596378712): \\?\C:\Users\中文文件夹\.android\build-cache

    错误如下: Error:Some file crunching failed, see logs for details Error:Execution failed for task ':app:m ...

  7. python 简明教程

    第一个源程序 #!/usr/bin/python# Filename : helloworld.pyprint 'Hello world' 执行: $ python helloworld.py 或者  ...

  8. 基于PhantomJS的网页抓取及写入文件

    # coding=utf-8 from selenium import webdriver from selenium.webdriver.common.desired_capabilities im ...

  9. (转)ASP连接sql server实例解析

    本文转载自:http://blog.csdn.net/xys_777/article/details/5696276 1.首先确定自己的iis没有问题 2.其次确定自己sqlserver没有问题 然后 ...

  10. 把MacBook里的电影导入到iPad

    主要是用iTunes -> 文件 -> 添加到资料库,然后选择影片 -> 同步 -> 应用.在iPad上点开视频APP即可. 怎样才能把mac里的电影放到ipad里_百度知道 ...