我有一个应用程序,我必须等待页面上显示一个按钮并单击它。该按钮是具有 id="next-arrow-button" 的按钮,但在父 div 上它具有 id="recorder-0"
按下此按钮后,该按钮将在几秒钟内不再显示。
您可以看到它具有相同的 id(id="next-arrow-button"),但在父 div 上它有另一个 id(id="recorder- 1 ",在它是 recoder- 0之前)
我等待元素可见并尝试单击它,但出现此错误:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
我的代码有点乱,但我想和你分享一个版本:
WebElement firstRecording = new WebDriverWait(driver, Constant.TIMEOUT_SECOND).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#recorder-0 #next-arrow-button")));
firstRecording.click();
new WebDriverWait(driver, Constant.TIMEOUT_SECOND).until(ExpectedConditions.stalenessOf(firstRecording));
WebElement secondRecording = new WebDriverWait(driver, Constant.TIMEOUT_SECOND).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#recorder-1 #next-arrow-button")));
secondRecording.click();
我试图删除该行:
new WebDriverWait(driver, Constant.TIMEOUT_SECOND).until(ExpectedConditions.stalenessOf(firstRecording));
但我得到同样的错误。
我是初级,如果我犯了一个愚蠢的错误,我很抱歉,但我真的需要你的帮助。谢谢 :)