[selenium] selenium+java+testNG 显示等待
2016-07-07 14:52
337 查看
触发后,在最长等待时间内返回了页面会立刻执行下一步,否则一直等待到设定的最长等待时间。显示等待比较节约时间。
WebDriverWait wait = new WebDriverWait(driver, 10); //最长等待时间为10秒
Wait.util(ExpectedConditions.Method())
public WebDriverdriver;
privateString url = "http://www.baidu.com/";
@Test
public void f() throws InterruptedException {
WebDriverWait wait= new WebDriverWait(driver,15);
try{
wait.until(ExpectedConditions.elementToBeClickable(By.id("su")));
//wait.until(ExpectedConditions.elementToBeSelected(locator));
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("su")));
wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//a[@name='tj_trnuomi']"),"糯米"));
wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath("//input[@type='submit']"),"百度一下"));
wait.until(ExpectedConditions.titleContains("百度一下,你就知道"));
}catch(TimeoutException e){
System.out.println("catchexecuted");
senior.TakeScreenshot.takeTakeScreenshot(driver);
e.printStackTrace();
}
}
WebDriverWait wait = new WebDriverWait(driver, 10); //最长等待时间为10秒
Wait.util(ExpectedConditions.Method())
等待条件 | Method() |
页面元素是否在页面上可用(enabled)和可被点击 | elementToBeClickable(By locator) |
页面元素处于被选中状态 | elementToBeSelected(WebElement element) |
页面元素在页面中存在 | presenseOfElementLocated(By locator) |
在页面元素中是否包含特定的文本 | textToBePresentInElementLocated(By locator, text) |
页面元素值 | textToBePresentInElementValue(By locator, value) |
标题(title) | title Contains(java.lang.String title) |
privateString url = "http://www.baidu.com/";
@Test
public void f() throws InterruptedException {
WebDriverWait wait= new WebDriverWait(driver,15);
try{
wait.until(ExpectedConditions.elementToBeClickable(By.id("su")));
//wait.until(ExpectedConditions.elementToBeSelected(locator));
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("su")));
wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//a[@name='tj_trnuomi']"),"糯米"));
wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath("//input[@type='submit']"),"百度一下"));
wait.until(ExpectedConditions.titleContains("百度一下,你就知道"));
}catch(TimeoutException e){
System.out.println("catchexecuted");
senior.TakeScreenshot.takeTakeScreenshot(driver);
e.printStackTrace();
}
}
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- 介绍一款信息管理系统的开源框架---jeecg
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- c++11 + SDL2 + ffmpeg +OpenAL + java = Android播放器
- 插入排序
- 冒泡排序
- 堆排序
- 快速排序
- 二叉查找树