I've been hitting my head against the wall trying to understand this and search Youtube, MSDN and this site but I can't move further with my scripts because of the StaleElementReferenceException. Here is the code:
//Opens the campaign gallery and Requests the template
driver.Url = "WEBSITE URL";
driver.FindElement(By.XPath("//input[@id='ctl00_ctl00_ctl00_Main_Main_Main_SearchTextBox']")).Click();
element.SendKeys("DPHR");
driver.FindElement(By.Id("ctl00_ctl00_ctl00_Main_Main_Main_SearchButton")).Click();
driver.FindElement(By.Id("ctl00_ctl00_ctl00_Main_Main_Main_rptCampaignTemplates_ctl00_gi_lnkGalleryRequest")).Click();
//Walks through the process of requesting the template and pushing it to pending status
driver.FindElement(By.Id("lnkGetStarted")).Click();
driver.FindElement(By.XPath("//form/div[9]/div/div[2]/div/div[2]/div[1]/div[3]/a/i")).Click();
Basically what is happening is I'm going through a gallery, and I'm trying to utilize the search box and enter text. But the exception gets thrown at
element.SendKeys("DPHR")
From what I can understand, it could be because once I click in the text box, the element refreshes and that error is thrown because its an "old" element. But I can't find any resource on how to circumvent this. Any insight is greatly appreciated!