显示等待

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. javascript 日期处理类库 moment.js

  2. AC日记——最大子段和 洛谷 P1115

    题目描述 给出一段序列,选出其中连续且非空的一段使得这段和最大. 输入输出格式 输入格式: 输入文件maxsum1.in的第一行是一个正整数N,表示了序列的长度. 第2行包含N个绝对值不大于10000 ...

  3. (3)Swing常用组件

    JTextField-文本框 继承自javax.swing.text.JTextComponent类

  4. Junit4 断言新方法

    话不多少说,直接上代码 package ASSERTTEST; import org.junit.Assert; import org.hamcrest.*;import org.junit.Test ...

  5. 洛谷 P2831 愤怒的小鸟

    P2831 愤怒的小鸟 题目描述 Kiana 最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于 (0,0)(0,0) 处,每次 Kiana 可以用它向第一象 ...

  6. pnputil

    http://mb.yidianzixun.com/article/0FYSZgnB?s=mb&appid=mibrowser C:\Users\Administrator>pnputi ...

  7. ganglia-monitoring-centos-linux

    http://www.tecmint.com/install-configure-ganglia-monitoring-centos-linux/ http://monitor.gitlab.net/ ...

  8. 【转】Code Your Own PHP MVC Framework in 1 Hour

      原文: https://www.codeproject.com/Articles/1080626/Code-Your-Own-PHP-MVC-Framework-in-Hour --------- ...

  9. Android命令行下蓝牙使用

    注意:此部分仅仅适用于broadcom 系列蓝牙芯片,比如RK903, AP6xxx 系列 通过su 命令切换到root 用户 1.先确认RFKILL 驱动已经载入 ls /sys/class/rfk ...

  10. spring 事件模式 源代码导读

    一,jdk 事件对象基类 package java.util; import java.io.Serializable; public class EventObject implements Ser ...