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

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

 

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

  }

  }


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值