【Selenium】显示、隐式等待
显示等待
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】显示、隐式等待的更多相关文章
- selenium的显示等待和隐式等待区别
1.selenium的显示等待 原理:显式等待,就是明确的要等到某个元素的出现或者是某个元素的可点击等条件,等不到,就一直等,除非在规定的时间之内都没找到,那么就跳出Exception.(简而言之:就 ...
- selenium的显示等待、隐式等待
转载:https://www.cnblogs.com/mabingxue/p/10293296.html Selenium显示等待和隐式等待的区别1.selenium的显示等待原理:显示等待,就是明确 ...
- selenium 隐式等待报错 value must be a non-negative integer
笔者运行代码使用selenium的隐式等待时出现报错: from selenium import webdriver # 从selenium导入webdriver import time driver ...
- Selenium+Java显示等待和隐式等待
描述:用来操作界面上的等待时间,显示等待是等待某一条件满足,条件满足后进行后面的操作:隐式等待是给出一个等待时间,在时间到达之前若满足条件,则立即执行后续操作. public class TestSe ...
- Selenium 定位元素原理,基本API,显示等待,隐式等待,重试机制等等
Selenium 如何定位动态元素: 测试的时候会遇到元素每次变动的情况,例如: <div id="btn-attention_2030295">...</di ...
- selenium中的三种等待方式(显示等待WebDriverWait()、隐式等待implicitly()、强制等待sleep())---基于python
我们在实际使用selenium或者appium时,等待下个等待定位的元素出现,特别是web端加载的过程,都需要用到等待,而等待方式的设置是保证脚本稳定有效运行的一个非常重要的手段,在selenium中 ...
- selenium的显示等待和隐式等待的区别
什么是显示等待和隐式等待?显示等待就是有条件的等待隐式等待就是无条件的等待 隐式等待 当使用了隐式等待执行测试的时候,如果 WebDriver没有在 DOM中找到元素,将继续等待,超出设定时间后则抛出 ...
- python+selenium显示等待、隐式等待和强制等待的区别
在实际使用selenium或者appium时,等待下个等待定位的元素出现,特别是web端加载的过程,都需要用到等待,而等待方式的设置是保证脚本稳定有效运行的一个非常重要的手段,在selenium中(a ...
- selenium相关导入By、Keys、WebDriverWait、ActionChains,显示等待与隐式等待
# -*- coding: utf-8 -*- """ @author: Dell Created on Tue Dec 24 12:33:56 2019 "& ...
- selenium 显示等待、隐式等待、强制等待
如今大部分web程序使用Ajax技术,当浏览器加载页面时,页面元素可能不是同时加载完成,如果因为加载某个元素超时导致ElementNotVisibleException的情况出现,自动化脚本的稳定性就 ...
随机推荐
- iOS7坐标上移44pt的解决
在iOS7中,引入一个新的属性,叫[UIViewController setEdgesForExtendedLayout:],它的默认值是UIRectEdgeAll.当容器为UINavigationC ...
- Debian9初始配置
1 进入root用户 su root 2 修改镜像源:编辑/etc/apt/sources.list文件 nano /etc/apt/sources.list 修改内容如下: deb http://m ...
- DTD概述
1. 什么是XML文件 可扩展标记语言,标准通用标记语言的子集,是用于标记电子文件使其具有结构性的标记语言. 2. 什么是dtd文件 DTD(文档类型定义)的作用是定义XML文档的合法构建模块.它使用 ...
- Spring 详解(三)------- SpringMVC拦截器使用
目录 不拦截静态资源 使用拦截器 拦截器使用测试 SimpleMappingExceptionResolver 拦截异常 不拦截静态资源 如果配置拦截类似于*.do格式的拦截规则,则对静态资源的访问是 ...
- 【spring boot】mybatis启动报错:Consider defining a bean of type 'com.newhope.interview.dao.UserMapper' in your configuration. 【Mapper类不能被找到】@Mapper 和@MapperScan注解的区别
启动报错: 2018-05-16 17:22:58.161 ERROR 4080 --- Disconnected from the target VM, address: '127.0.0.1:50 ...
- mac 安装ANT
http://blog.csdn.net/crazybigfish/article/details/18215439 1.下载ant:官网下载 当前最新版是Apache Ant 1.9.3,可以下载那 ...
- 创建注记图层C# IFeatureWorkspaceAnno
http://blog.csdn.net/mydriverc/article/details/1675613 //IFeatureWorkspaceAnno Example //The ...
- BUPT复试专题—排序(2009)
题目描述 查找序列a 中小于 b 的第 i 个数的数的个数 输入 输入有多组,每组四行第一行:序列a个数N第二行:(序列a的)N个数,升序排列第三行:序列b个数M 第四行:(序列b的)M个数,升序排列 ...
- 用rsync命令删除大文件夹
删除大文件夹 rsync 命令做同步文件用的命令 我们可以借助其快速的运行 来对大文件夹删除:原来就是 新建一个空文件夹 然后把这个空文件夹同步到一个大文件夹下面: 这样会删除大文件夹下面的内容 是高 ...
- AnimalWindow使用,实现界面动态消失
http://m.blog.csdn.net/blog/shufac/24932279 http://blog.sina.com.cn/s/blog_455245fc01000a42.html Ani ...