转自:https://www.cnblogs.com/ella-yao/p/7778678.html

WebDriverWait介绍

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");
}
});

}

}

WebDriverWait介绍的更多相关文章

  1. xlrd的使用详细介绍以及基于Excel数据参数化实例详解

    1.安装xlrd xlrd是python用于读取excel的第三方扩展包,所以在使用xlrd前,需要使用以下命令来安装xlrd.pip install xlrd 在使用这个命令之前先确定自己有没有安装 ...

  2. Selenium常用API详解介绍

    转至元数据结尾   由 黄从建创建, 最后修改于一月 21, 2019 转至元数据起始   一.selenium元素定位 1.selenium定位方法 2.定位方法的用法 二.控制浏览器操作 1.控制 ...

  3. 移动端自动化测试(二)之 Appium常用的API(python)函数介绍

    上一章节已经介绍了Appium的环境搭建,其实只要掌握了Appium的工作原理,前期的准备工作和安装过程是比较简单的.那么当我们搭建好Appium环境后接下来做些什么呢?通常思路是开始appium的第 ...

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

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

  5. 9.0 toast定位+WebDriverWait显示等待

    Toast  判断-----基本操作问题 首先基本操作,进入安卓市场的账号密码页面--- from appium import webdriver from selenium.webdriver.su ...

  6. 爬虫、网页测试 及 java servlet 测试框架等介绍

    scrapy 抓取网页并存入 mongodb的完整示例: https://github.com/rmax/scrapy-redis https://github.com/geekan/scrapy-e ...

  7. selenium2基本控件介绍及其代码

    输入框:input  表现形式:      1.在html中一般为:<input id="user" type="text"> 主要操作:    ...

  8. python基础 — Selenium 详细介绍

    一.Selenium+Python环境搭建及配置 1.1 selenium 介绍 selenium 是一个 web 的自动化测试工具,不少学习功能自动化的同学开始首选 selenium ,因为它相比 ...

  9. 详解介绍Selenium常用API的使用--Java语言(完整版)

    参考:http://www.testclass.net/selenium_java/ 一共分为二十个部分:环境安装之Java.环境安装之IntelliJ IDEA.环境安装之selenium.sele ...

随机推荐

  1. 原创:各种normalize函数实现的性能和精度大比拼

    ///////////////////////////////////////////////////////////////////////// // // Performance benchmar ...

  2. 域适应(Domain adaptation)

    定义 在迁移学习中, 当源域和目标的数据分布不同 ,但两个任务相同时,这种 特殊 的迁移学习 叫做域适应 (Domain Adaptation). Domain adaptation有哪些实现手段呢? ...

  3. 【程序】必看干货:Photon多人游戏开发教程

    PUN介绍 http://vibrantlink.com/ 入门 Photon Unity Networking(首字母缩写PUN)是一个Unity多人游戏插件包.它提供了身份验证选项.匹配,以及快速 ...

  4. pc端美化select,jquery获取select中的option的text值

      代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  5. LoadRunner12_脚本中运行JavaScript

    版权声明:本文为博主原创文章,未经博主允许不得转载. [系统及软件配置] LR版本:12.53 JDK版本:1.8 函数:web_js_run,该函数仅在LR12版本提供支持,LR11不支持JavaS ...

  6. expect--脚本实现免交互命令

    转自:http://blog.51cto.com/lizhenliang/1607723 注意:使用expect脚本时,需要把脚本添加执行权限,然后./test.sh直接执行,不能用sh或者sourc ...

  7. 2016级算法第一次练习赛-C.斐波那契进阶

    870 斐波那契进阶 题目链接:https://buaacoding.cn/problem/870/index 思路 通过读题就可以发现这不是一般的求斐波那契数列,所以用数组存下所有的答案是不现实的. ...

  8. 如何解决 “invalid resource directory name”, resource “crunch”

    Ant and the ADT Plugin for Eclipse are packing the .apk file in a different build chain and temp gen ...

  9. 【翻译】理解 LSTM 及其图示

    目录 理解 LSTM 及其图示 本文翻译自 Shi Yan 的博文 Understanding LSTM and its diagrams,原文阐释了作者对 Christopher Olah 博文 U ...

  10. MySQL中optimize的作用

    MySQL执行命令delete语句时,如果包括where条件,并不会真正的把数据从表中删除,而是将数据转换成了碎片,通过下面的命令可以查看表中的碎片数量和索引等信息: mysql > show ...