转载: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,感谢博文,学习了 原文: 发现太多人不会用等待了,博主今天实在是忍不住要给 ...
随机推荐
- linux下分割和重组文件
linux shell命令里的split和cat命令可以轻松完成这两个功能,举个例子来说,比如一个1GB大小的文件foo.zip,以100M为块分割: 分割: split -b 100M -d foo ...
- Linux 系统应用编程——进程基础
一.Linux下多任务机制的介绍 Linux有一特性是多任务,多任务处理是指用户可以在同一时间内运行多个应用程序,每个正在执行的应用程序被称为一个任务. 多任务操作系统使用某种调度(shedule)策 ...
- Roman to Integer(将罗马数字转成整数)
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...
- SQL 逻辑优化 case when 转为 union all
通常数据库的优化从硬件层面去考虑可分为4个方面: CPU:即降低计算复杂度,如减少sql各类聚合函数,窗口函数,case when等. IO :(较少查询结果集过程中对数据的访问量.数据优化很大程度从 ...
- python编码详解--转自(Alex的博客)
原文地址:http://www.cnblogs.com/alex3714/articles/7550940.html 编码回顾 在备编码相关的课件时,在知乎上看到一段关于Python编码的回答 这哥们 ...
- Day19 Django
老师代码博客: http://www.cnblogs.com/yuanchenqi/articles/7552333.html 上节内容回顾: class Book(models.Model): ti ...
- DjangoRestFramework实践笔记
1.Restful服务的实现方式一共三种:function based view,class based view,viewset+router,这三种实现方式的封装重度依序升高,越往后越适合典型CU ...
- Commandline OpenVPN client on Mac OSX with macports
http://www.tuicool.com/articles/FjuyQj 注:文中有些内容做了修改,特别是那个配置文件,不能直接抄着用. Most people use TunnelBrick ...
- 基类包括字段“ScriptManager1”,但其类型(System.Web.UI.ScriptManager)与控件(System.Web.UI.ScriptManager)的类型不兼容
首先说下原先的情况,就是原本老项目的Web解决方案是使用.net framework 2.0的老版本, 所以机器也安装过Microsoft ASP.NET 2.0 AJAX Extensions..A ...
- 会话机器人Chatbot的相关资料
Chatbot简介 竹间智能简仁贤:打破千篇一律的聊天机器人 | Chatbot的潮流 重点关注其中关于情感会话机器人的介绍 当你对我不满的时候我应该怎么应对,当你无聊,跟我说你很烦的时候,我应该怎么 ...