Appium自动化测试第八篇WebDriverWait使用

 WebDriverWait使用如下

(new WebDriverWait(driver,6))
                .until(ExpectedConditions.presenceOfElementLocated(By by)).click();

ExpectedConditions的一些方法:
1.titleIs( String title)
判断当前页面的title是否精确等于预期
2.titleContains( String title)
判断当前页面的title是否包含预期字符串
3.urlToBe( String url)
判断当前页面的url是否精确等于预期
4.urlContains( String fraction)
判断当前页面的url是否包含预期字符串
5.urlMatches( String regex)
6.presenceOfElementLocated( By locator)
判断页面元素是否出现,在等待时间内没有出现就抛出异常
7.visibilityOfElementLocated( By locator)
判断元素是否出现
8.alertIsPresent()
9.elementToBeSelected
元素是否可以被点击
10.elementToBeClickable
复选框是否可以被点击
11.textToBePresentInElement
判断字样是否在元素中显示
 

    WebDriverWait wait = new WebDriverWait( Driver.getCurrentDriver(),10);
	      //调用ExpectedConditions的titleContains方法判断页面title属性是否包含"xueqiu"字段
	      wait.until(ExpectedConditions.titleContains("xueqiu"));

	      wait.until(ExpectedConditions.titleIs("雪球"));
	      
	      WebElement select = Driver.getCurrentDriver().findElement(By.xpath("//option[@id='peach']"));
	      //elementToBeSelected(Element element)判断"peach"是否被选中
	      wait.until(ExpectedConditions.elementToBeSelected(select));

	      //elementToBeClickable(String )判断复选框对象是否可以被点击
	      wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//p")));

	      //presenceOfElementLocated 判断元素是否存在
	      wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//x")));

	      //textToBePresentInElement判断字样是否在元素中显示
	      WebElement p = Driver.getCurrentDriver().findElement(By.xpath("//p"));
	      wait.until(ExpectedConditions.textToBePresentInElement(p, "select ur perfer fruit"));
	      wait.until(ExpectedConditions.urlContains(""));
	      wait.until(ExpectedConditions.alertIsPresent());

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员路同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值