I'm using 3.9.1 version of selenium with Java to automate the testing of a web application. On clicking a button on the page, some dynamic content is loaded. The page thus refreshes whenever this button is clicked. A java script runs on button click and updates the DOM IMO. So, at this instant, the button (which is visible on the page), cannot be accessed & I get a staleElementReferenceException.
So, my question is, does Selenium automatically reload the DOM once it changes? I am relatively new to selenium. I did some basic research and refreshed the page using driver.navigate().Refresh() to check if my problem gets solved. And, it doesn't work. Any pointers will be deeply appreciated.