StaleElementReferenceException

This is an exception that you will quite often see when you work with AJAX or JavaScript-heavy websites, where the DOM is continually being manipulated.

You are probably used to seeing code like this:

WebElement googleSearchBar = driver.findElement(By.name("q"));

The WebElement object that you have created is actually a reference to a specific element in the DOM. Think of it as a phone number that you call to talk to the element.

StaleElementReferenceException

A WebElement refers to an element in the DOM.

When the DOM is manipulated and the old element is destroyed, that reference no longer links to an element in the DOM, and it becomes stale. Using ...

Get Mastering Selenium WebDriver now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.