0

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.

JBJ
  • 173
  • 1
  • 1
  • 15
  • if (activeDir.Text is "Active Directory") { xrmBrowser.Driver.FindElement(By.XPath("//*[text()='Active Directory']")).Click(); Log.Info("AD Click"); } – Sooraj Dec 02 '19 at 09:06
  • What you mean @SoorajSathianandan – JBJ Dec 02 '19 at 09:12
  • You need to build the activeDir web element again after you get the text in the if condition. The code is in my previous comment. – Sooraj Dec 02 '19 at 09:21
  • Sorry @SoorajSathianandan No luck, it still fails – JBJ Dec 02 '19 at 09:25

0 Answers0