我知道当DOM树发生变化时会抛出异常,解决方法是在刷新后再次查找元素,但是...
我正在做以下手术:
sessionsView.filterSession(sessionName);
lockSession();
approveSession();
completeSession();
在执行开始时,此代码completeButton
被禁用,如下所示:
<button _ngcontent-mfo-c209="" class="btn btn-default btn-xs pull-right" style="margin-right: 10px;" disabled="">Complete</button>
锁定和批准操作由rest API服务完成."批准完成"按钮启用后,我会在刷新后查找它,然后try 单击它.
public void completeSession() {
By completeButtonByXpath = By.xpath("*//button[text()='Complete']");
WebElement completeButton = driver.findElement(completeButtonByXpath);
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(completeButton));
completeButton.click();
}
但我收到
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
当我点击completeButton
我也try 过这样的等待
有什么解决办法吗?