I have an application where I have to wait for a button to be visible on the page and click on it. The button is the one that has id="next-arrow-button", but on the parent div it has id="recorder-0"
After pressing on this button, the button won't be displayed anymore for a couple of seconds.
The button is displayed again like this:
You can see that it has the same id ( id="next-arrow-button"), but on the parent div it has another id ( id="recorder-1" , before it was recoder-0)
I wait for the element to be visible and I try to click on it, but I got this error:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
My code is a bit messy, but I want to share with you a version of it:
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();
I tried to remove the line:
new WebDriverWait(driver, Constant.TIMEOUT_SECOND).until(ExpectedConditions.stalenessOf(firstRecording));
But I get the same error.
I am junior and I am sorry if I am doing a stupid mistake, but I really need you help. Thank you :)