显示等待

WebDriverWait

超时抛出TimeOutException,默认500毫秒

public class WaitToReturnElement {

   /*
* 设置超时时间为5秒,返回指定xpath的WebElement
* */
public static WebElement waitForByXpath(final WebDriver driver,final String xpath) {
WebDriverWait wait = new WebDriverWait(driver, 5);
return wait.until(new ExpectedCondition<WebElement>() { public WebElement apply(WebDriver arg0) {
return driver.findElement(By.xpath(xpath));
} });
} /*
* 设置超时时间为10秒,返回指定id的WebElement
* */
public static WebElement waitForById(final WebDriver driver,final String id) {
WebDriverWait wait = new WebDriverWait(driver, 10);
return wait.until(new ExpectedCondition<WebElement>() { public WebElement apply(WebDriver arg0) {
return driver.findElement(By.id(id));
} });
} /*
* 设置超时时间为10秒,返回指定xpath的WebElement是否出现
* */
public static Boolean isElementDisplayed(final WebDriver driver,final String xpath) {
WebDriverWait wait = new WebDriverWait(driver, 10);
return wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver arg0) {
return driver.findElement(By.xpath(xpath)).isDisplayed();
}
});
} }

ExpectedCondition

等待元素直到可点击状态
WebDriverWait wait=new WebDriverWait(driver,10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("")));

隐式等待

查找WebDriver无法使用的元素时等待,默认0,生命周期整个WebDriver

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

【Selenium】显示、隐式等待的更多相关文章

  1. selenium的显示等待和隐式等待区别

    1.selenium的显示等待 原理:显式等待,就是明确的要等到某个元素的出现或者是某个元素的可点击等条件,等不到,就一直等,除非在规定的时间之内都没找到,那么就跳出Exception.(简而言之:就 ...

  2. selenium的显示等待、隐式等待

    转载:https://www.cnblogs.com/mabingxue/p/10293296.html Selenium显示等待和隐式等待的区别1.selenium的显示等待原理:显示等待,就是明确 ...

  3. selenium 隐式等待报错 value must be a non-negative integer

    笔者运行代码使用selenium的隐式等待时出现报错: from selenium import webdriver # 从selenium导入webdriver import time driver ...

  4. Selenium+Java显示等待和隐式等待

    描述:用来操作界面上的等待时间,显示等待是等待某一条件满足,条件满足后进行后面的操作:隐式等待是给出一个等待时间,在时间到达之前若满足条件,则立即执行后续操作. public class TestSe ...

  5. Selenium 定位元素原理,基本API,显示等待,隐式等待,重试机制等等

    Selenium  如何定位动态元素: 测试的时候会遇到元素每次变动的情况,例如: <div id="btn-attention_2030295">...</di ...

  6. selenium中的三种等待方式(显示等待WebDriverWait()、隐式等待implicitly()、强制等待sleep())---基于python

    我们在实际使用selenium或者appium时,等待下个等待定位的元素出现,特别是web端加载的过程,都需要用到等待,而等待方式的设置是保证脚本稳定有效运行的一个非常重要的手段,在selenium中 ...

  7. selenium的显示等待和隐式等待的区别

    什么是显示等待和隐式等待?显示等待就是有条件的等待隐式等待就是无条件的等待 隐式等待 当使用了隐式等待执行测试的时候,如果 WebDriver没有在 DOM中找到元素,将继续等待,超出设定时间后则抛出 ...

  8. python+selenium显示等待、隐式等待和强制等待的区别

    在实际使用selenium或者appium时,等待下个等待定位的元素出现,特别是web端加载的过程,都需要用到等待,而等待方式的设置是保证脚本稳定有效运行的一个非常重要的手段,在selenium中(a ...

  9. selenium相关导入By、Keys、WebDriverWait、ActionChains,显示等待与隐式等待

    # -*- coding: utf-8 -*- """ @author: Dell Created on Tue Dec 24 12:33:56 2019 "& ...

  10. selenium 显示等待、隐式等待、强制等待

    如今大部分web程序使用Ajax技术,当浏览器加载页面时,页面元素可能不是同时加载完成,如果因为加载某个元素超时导致ElementNotVisibleException的情况出现,自动化脚本的稳定性就 ...

随机推荐

  1. ci框架——文章查看之上篇下篇

    1:从数据库查询出推荐的文章的信息,循环查出每篇推荐文章的id和title; foreach($data as $val){ $dataid[]=$val->aid; $datatitle[]= ...

  2. 在Oracle Linux上安装dtrace

    http://www.ohsdba.cn/index.php?g=Home&m=Article&a=show&id=171   时间: 2016-10-09 00:40:04 ...

  3. [Testing] Config jest to test Javascript Application -- Part 3

    Run Jest Watch Mode by default locally with is-ci-cli In CI, we don’t want to start the tests in wat ...

  4. UP board 漫谈——从Atom到UP Board

    前言 原创文章,转载引用务必注明链接.如有疏漏,欢迎指正. 图文部分引用自CNXSoft ​ 每块开发板都有其设计理念,也是其特色所在.有做工优良.接口丰富的多媒体全能开发板Lemaker Guita ...

  5. HDU 4902 Nice boat 线段树+离线

    据说暴力也过了.还傻逼地写了这么长. . . #include <stdio.h> #include <string.h> #include <math.h> #i ...

  6. mysql中游标在存储过程中的具体使用方法

    昨天写的一个东东,分享下给大家. drop PROCEDURE  if exists sp_cleanUserData; CREATE  PROCEDURE `sp_cleanUserData`()  ...

  7. Ikki&#39;s Story IV - Panda&#39;s Trick (poj 3207 2-SAT)

    Language: Default Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072K Total S ...

  8. ios系统铃声调用方法

    首先,这里我要说明这里并非真正调用系统内部自带的铃声,由于苹果是不同意开发人员调用的,没有给开发人员接口.假设调用了就无法上线的! 那为什么AppStore里面还有那么多app显示的效果是调用系统的铃 ...

  9. html中跳转方法(含设定时间)

    脚本方式 如: <script language="JavaScript" type="text/JavaScript"> <!-- wind ...

  10. JavaScript你所不知道的困惑(2)

    困惑一: var obj1 = new Object(); var obj2 = obj1; obj1.name = "阳光小强"; alert(obj2.name); //输出结 ...