如何等待属性? java + webdriver

时间:2016-03-07 14:08:08

标签: java selenium automation

我需要等待属性收到值并得到关于“until”的错误。我做错了什么?谢谢

List<WebElement> messages = driver.findElements(By.className("message-item"));
//select last message
WebElement lastMessage = messages.get(messages.size() - 1);
//wait for last message attribute received failed
WebDriverWait waitLastMessage = new WebDriverWait(driver, 10);
waitLastMessage.until(lastMessage.getAttribute("data-deliverystatus").contains("failed"));
//here i check vaules of attribute
Assert.assertEquals(lastMessage.getAttribute("data-deliverystatus"), "failed");

1 个答案:

答案 0 :(得分:0)

until方法收到ExpectedConditions,而不是boolean。你可以做那样的事情(未经测试)

private ExpectedCondition<Boolean> waitForAttribute(final WebElement element) {
    return new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {
            return element.getAttribute("data-deliverystatus").contains("failed");
        }
    };
}

WebDriverWait waitLastMessage = new WebDriverWait(driver, 10);
waitLastMessage.until(waitForAttribute);