我正在尝试验证元素的属性"innerText“是否已更新(例如,从100更新为50)。为了避免使用休眠,我在等待attributeToBe。但是我收到了StaleElementReferenceException异常。可能是因为DOM被重新加载了。重要提示:元素是可见的,存在的,如果没有这个元素,element.getText()将返回旧值。因此测试失败(因为该属性具有旧值)。
现在,我忽略了这个例外,但是你能建议一个更好的解决方案吗?
public void waitAttributeToBe(WebElement webElement, String text) {
try {
wait.until(ExpectedConditions.attributeToBe(webElement,"innerText", text));
} catch (StaleElementReferenceException exc) {
exc.printStackTrace();
}
}例外:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document发布于 2020-09-28 22:17:46
如果有人需要帮助,我使用元素定位器来修复它,而不是在参数中传递webelement。这就是我使用StaleElementReferenceException的原因,因为元素正在刷新,而我正在访问旧的元素。
public void waitAttributeToBe(By by, String attribute, String text) {
wait.until(ExpectedConditions.attributeToBe(by, attribute, text));
}https://stackoverflow.com/questions/63914977
复制相似问题