转载:selenium的wait.until()
package com.test.elementwait;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ExplicitWait {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.baidu.com");
driver.manage().window().maximize();
//标题是不是“百度一下,你就知道”
new WebDriverWait(driver,5).until(ExpectedConditions.titleIs("百度一下,你就知道"));
//标题是不是包含“百度一下”
new WebDriverWait(driver,5).until(ExpectedConditions.titleContains("百度一下"));
//判断该元素是否被加载在DOM中,并不代表该元素一定可见
new WebDriverWait(driver,5).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='kw']")));
//判断元素(定位后)是否可见
new WebDriverWait(driver,5).until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//*[@id='kw']"))));
//判断元素是否可见(非隐藏,并且元素的宽和高都不等以0)
new WebDriverWait(driver,5).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='kw']")));
//只要存在一个就是true
ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[@id='kw']"));
//元素中的text是否包含语气的字符串
ExpectedConditions.textToBePresentInElementLocated(By.xpath("//*[@id='kw']"), "百度一下");
//元素的value属性中是否包含语气的字符串
ExpectedConditions.textToBePresentInElementValue(By.xpath("//*[@id='kw']"), "***");
//判断该表单是否可以切过去,可以就切过去并返回true,否则放回false
ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("**"));
//判断某个元素是否不存在于DOM或不可见
ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@id='kw']"));
//判断元素是否可以点击
ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='kw']"));
//等到一个元素从DOM中移除
ExpectedConditions.stalenessOf(driver.findElement(By.xpath("//*[@id='kw']")));
//判断某个元素是否被选中,一般用在下拉列表
ExpectedConditions.elementToBeSelected(By.xpath("//*[@id='kw']"));
//判断某个元素的选中状态是否符合预期
ExpectedConditions.elementSelectionStateToBe(By.xpath("//*[@id='kw']"), true);
//判断某个元素(已定位)的选中状态是否符合预期
ExpectedConditions.elementSelectionStateToBe(driver.findElement(By.xpath("//*[@id='kw']")), false);
//判断页面中是否存在alert
new WebDriverWait(driver,5).until(ExpectedConditions.alertIsPresent());
//--------------------自定义判断条件-----------------------------
WebDriverWait wait = new WebDriverWait(driver, 3);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return !driver.findElement(By.xpath("//*[@id='kw']")).getAttribute("class").contains("x-form-invalid-field");
}
});
}
}
转载:selenium的wait.until()的更多相关文章
- [转载]Selenium実行中にJavaScriptのコードを実行する
Selenium実行中にJavaScriptのコードを実行する JavaScriptで画面の値を取得/設定するコードをメモ. WebDriverEx.cs // JavaScriptを実行(戻り値なし ...
- selenium定位元素(本内容从https://my.oschina.net/flashsword/blog/147334处转载)
注明:本内容从https://my.oschina.net/flashsword/blog/147334处转载. 在使用selenium webdriver进行元素定位时,通常使用findElemen ...
- (转载)自动化基础普及之selenium是啥?
转载:http://www.cnblogs.com/fnng/p/3980093.html Selenium 并不像QTP那样让人一下子就明白是什么?它是编程人员的最爱,但它却对测试新手产生了很大的阻 ...
- 转载 基于Selenium WebDriver的Web应用自动化测试
转载原地址: https://www.ibm.com/developerworks/cn/web/1306_chenlei_webdriver/ 对于 Web 应用,软件测试人员在日常的测试工作中, ...
- Selenium+TestNG+Maven+Jenkins+SVN(转载)
转载自:https://blog.csdn.net/u014202301/article/details/72354069 一. 创建Maven项目,下载Selenium和TestNG的依赖(依赖可以 ...
- 【转载】Selenium WebDriver的简单操作说明
转载自:http://blog.csdn.net/xiao190128/article/details/49784121 1.打开一个测试浏览器 对浏览器进行操作首先需要打开一个浏览器,接下来才能对浏 ...
- Selenium Webdriver元素定位的八种常用方式(转载)
转载自 https://www.cnblogs.com/qingchunjun/p/4208159.html 在使用selenium webdriver进行元素定位时,通常使用findElement或 ...
- Python + Selenium 实现对页面的指定元素截图(可截长图元素)【转载】
先在首页上执行一段 JavaScript 脚本,将页面的滚动条拖到最下方,然后再拖回顶部,最后才截图.这样可以解决那种按需加载图片的情况 以下代码为转载别处博客改造后的,有chrome和ff两种浏览器 ...
- [python爬虫] Selenium常见元素定位方法和操作的学习介绍(转载)
转载地址:[python爬虫] Selenium常见元素定位方法和操作的学习介绍 一. 定位元素方法 官网地址:http://selenium-python.readthedocs.org/locat ...
- 【转载】一定要会用selenium的等待,三种等待方式必会
转载地址:http://blog.csdn.net/huilan_same/article/details/52544521,感谢博文,学习了 原文: 发现太多人不会用等待了,博主今天实在是忍不住要给 ...
随机推荐
- Jquery的过滤选择器分为哪几种?
Jquery的过滤选择器分为哪几种? 转载▼ 标签: jquery 过滤选择器 分类 分类: JQuery 所有的过滤选择器分为哪几种: 一.基本过滤选择器(重点掌握下列八个) :first 选取第一 ...
- CentOS6.5 64位下安装部署Ansible
这里使用的软件包为一下版本 Python-2.7.12.tgz pip-9.0.1.tar.gz ansible-2.2.0.0.tar.gz 其他依赖包使用pip方式安装 方便说明做以下设定: 控制 ...
- ffmpeg 在windows 上编译
我在网上看到了一些资料,但是很多都不怎么全,而且 总会碰到这样或那样的问题,下面是我的一些经验,分享一下,当然也参考了大侠们的东西呵呵! 环境: OS:windows mingw +yasm+fmpe ...
- 浅谈这个时代的SEO与网络营销
1.大网站对分享内容的审核越来越严,高质量借道外链越来越难做. 2.大搜索引擎入口的权威性将会不断受各种方面的的削弱:比如自媒体.垂直服务网站等 3.旧路还没有短,但是新路要积极挖掘. 这也说的太少了 ...
- CDN公共资源
SAE: http://lib.sinaapp.com/ Google: https://developers.google.com/speed/libraries/devguide?hl=zh-CN ...
- mysql高级之编程优化
★编程优化一.字符编码(mysql控制台乱码输出解决:character_set_results='gbk')表/列编码设置 列:alter table 表名 change 列名 列名 数据类型 c ...
- Apache 流框架 Flink,Spark Streaming,Storm对比分析(一)
本文由 网易云发布. 1.Flink架构及特性分析 Flink是个相当早的项目,开始于2008年,但只在最近才得到注意.Flink是原生的流处理系统,提供high level的API.Flink也提 ...
- React+ANTD项目使用后的一些关于生命周期比较实用的心得
1. constructor() constructor(props){ super(props) this.state=({ }) } 一定先写super 可以接收从父组件传来的值 父组件往子组件 ...
- C# 获取文件下载的各种方法
public class RemoteDownload { public static void DownLoad(string addressUrl,string localName) { //下载 ...
- unix中的rm,rmdir的使用
一.rm的使用 1.基本用法:用于删除文件 rm filename 2.可加属性值 (1)-v rm -v filename 作用:提示删除的情况 (2)-f rm -f filename 作用:删 ...