Error stale element reference element is not attached to the page document

+1 vote

I’m getting an error when using selenium for my app which is built in C#.

OpenQA.Selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document

IWebElement e = driver.FindElement(By.XPath(link_click), 10);

e.Click();

The error line is in the e.Click() but this was working fine earlier by using same XPath but failed on the last try. How can I fix it?

Jul 9, 2018 in Selenium by Martin
• 4,320 points
49,640 views
I am lucky to find this site! Interesting.
Hi Davidrania, welcome to the Community. It's like a one-stop place for all your questions. You can ask questions related to any technologies and the response time is really good.

2 answers to this question.

0 votes

It means that either the element changed in the page, or element gets deleted.You should try again, like this:

bool staleElement = true; 

while(staleElement){

  try{

     driver.FindElement(By.XPath(link_click), 10).Click();

     staleElement = false;


  } catch(StaleElementReferenceException e){

    staleElement = true;

  }

}

answered Jul 9, 2018 by Samarpit
• 5,890 points
Thanks......I resolved the issue.
thanks bro its working for me.
Hi Please tell how to implement this solution in protractor
Hey, @Rahul I'd recommend you using browser.wait and Expected Conditions to solve this issue.
Perfect. Thanks. it's worked for me.
Great!!! worked for me... :)
+1 vote
go to your code and apply implicit wait with the Web Driver.

Thanks
answered Dec 21, 2018 by Malik
Hey @Malik it doesn't help.

Related Questions In Selenium

+1 vote
0 answers

python selenium error: element is not attached to the page document

I am scraping Banggood, the problem is ...READ MORE

Apr 10, 2020 in Selenium by eslam
• 130 points
8,438 views
+1 vote
2 answers
0 votes
1 answer

To check that the web page is loaded or not using Selenium Web Driver?

The solution is using Implicit Wait which ...READ MORE

answered May 24, 2018 in Selenium by Meci Matt
• 9,460 points
22,928 views
0 votes
2 answers

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,500 points
8,153 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
7,242 views
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,890 points
4,982 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
6,201 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP