You probably will come across the following error frequently when writing Selenium test case for a Ajax-rich website.
- Error: Element not found in the cache – perhaps the page has changed since it was looked up
This is because the Selenium WebDriver reference to your element would now be stale as the DOM has been modified by Ajax. To resolve the problem in Java, you can make us of the WebDriverWait and find the element each time before you use it.
public void clickAnElementByLinkText(String linkText) { new WebDriverWait(driver, 25).until(ExpectedConditions.presenceOfElementLocated(By.linkText(linkText))); driver.findElement(By.linkText(linkText)).click(); }
Done =)