appium显示等待

方式1:

WebDriverWait wait= new WebDriverWait(driver, 5 * 60, 1 * 1000);
// 显示等待元素出现
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("fdkasfjdaskljf"))); 

方式2:

WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement xxxx= wait.until(new ExpectedCondition<WebElement>() {
    @Override
    public WebElement apply(WebDriver arg0) {
        return driver.findElement(By.xpath("abcdefg"));
    }
});
xxxx.click();

方式3:

WebDriverWait wait = new WebDriverWait(driver, 60);
list = wait.until(new ExpectedCondition<List<WebElement>>() {
    @Override
    public List<WebElement> apply(WebDriver arg0) {
        return driver.findElements(By.xpath("abcdefghijklmn"));
    }
});


方式4:
int counter = 1;
//显⽰等待,⽤10s读取元素,如果读取不到将抛出异常,每500ms读取⼀次。
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
bool flag = wait.Until<bool>((d) =>{
                Console.WriteLine(counter.ToString());
                counter++;
                return counter == 5;
});


           

"ExpectedConditions.visibilityOfElementLocated"和"ExpectedConditions.presenceOfElementLocated"之间的确切区别是什么?

WebDriverWait wait = new WebDriverWait(driver, 5 * 60, 1 * 1000);

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[text()='Show advanced settings...']"))).click();

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[text()='Show advanced settings...']"))).click();

visibilityOfElmementLocated检查元素是否存在且是否可见.要检查可见性,请确保元素的高度和宽度大于0.

presenceOfElementLocated只检查dom以查看它是否可以定位元素,无论其可见性如何.

资料来源:https//selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html#visibilityOf-org.openqa.selenium.WebElement-

visibilityOf public static ExpectedCondition visibilityOf(WebElement element)期望检查已知存在于页面DOM上的元素是否可见.可见性意味着元素不仅会显示,而且高度和宽度也大于0.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值