Using C# and Selenium, while clicking a text in the window the page gets refreshed. Right after the click, it's throwing StaleElementReferenceException
xrmBrowser.CommandBar.ClickCommand("Warranty");
xrmBrowser.ThinkTime(8000);
xrmBrowser.Driver.LastWindow();
Log.Info("Look for Active directory button");
var activeDir = xrmBrowser.Driver.FindElement(By.XPath("//*[text()='Active Directory']"));
if (activeDir.Text is "Active Directory")
{
activeDir.Click();
Log.Info("AD Click");
}
Log is printing Look for Active directory button but not AD Click
The Active Directory link is getting clicked and the below error is thrown rightaway
exception: OpenQA.Selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document (Session info: chrome=78.0.3904.108) (Driver info: chromedriver=2.38.551601 (edb21f07fc70e9027c746edd3201443e011a61ed),platform=Windows NT 10.0.17763 x86_64)
On Click of Active Directory the page will refresh with some other content. The next step is to find the heading in that page as below
var headingElementOnPage = xrmBrowser.Driver.FindElement(By.TagName("h2"));
Any quick help is appreciated.