您的位置:首页 > 编程语言 > Java开发

[selenium] selenium+java+testNG 显示等待

2016-07-07 14:52 337 查看
触发后,在最长等待时间内返回了页面会立刻执行下一步,否则一直等待到设定的最长等待时间。显示等待比较节约时间。

 

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)
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();

  }
  }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息