StaleElementReferenceException in Selenium

0 votes
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.
Mar 29, 2018 in Selenium by Shubham
• 13,290 points
44 views

1 answer to this question.

0 votes
Since the page gets refreshed, the button referenced, is to the button on the old page which no longer exists. So, your best solution is by getting a new reference to the button on the refreshed page (eg call FindElementById).
answered Mar 29, 2018 by nsv999
• 5,090 points

Related Questions In Selenium

0 votes
1 answer

Selenium ChromeDriver issue - Want to run it in background, but not as headless browser

This is a flaw with ChromeDriver. Tried ...READ MORE

answered Mar 26, 2018 in Selenium by nsv999
• 5,090 points
947 views
0 votes
2 answers

Finding an element in Selenium

Hi, ​both find_element_by_xpath(xpath) and find_element(By.XPath, xpath) serve the ...READ MORE

answered Aug 23 in Selenium by Abha
• 22,870 points
120 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,090 points
1,965 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
554 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
888 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
550 views
0 votes
3 answers

How to specify "ENTER" button functionality in Selenium WebDriver code?

using OpenQA.Selenium.Interactions; Actions builder = new Actions(driver); ...READ MORE

answered Feb 12 in Selenium by anonymous
8,777 views
0 votes
2 answers