I am new to Selenium and I am getting a StaleElementReferenceException error but not sure why. I have tried to debug to no avail. It would be great if someone could point me to the issue. I have posted below links to the code on Gist and the stack trace as well.
EditCustomerPage.java This is the page object file Error is on Line 34.
EditCustomer This is the test
A StaleElementReferenceException is a specific type of exception that is thrown when a web driver is trying to interact with a web page element that is no longer present in the DOM (Document Object Model).
This can happen when the page is refreshed, or when an element on the page is replaced with a new element, for example, as a result of an AJAX request.
This error usually means that the element you are trying to interact with no longer exist. You should try to find the element again.
This can occur in Selenium webdriver (Java), where one common cause of this error occurs when the element is located after a page refresh or navigation, thus you will need to handle the wait and find the
element again using the updated DOM.
You can handle this exception by using the following
You could try
It's also worth noting that this exception could also be thrown by other ways like when navigating to different pages on your application and then trying to interact with elements on the previous page.