Q: Selecting list values automatically results in StaleElementReferenceException In my search page I have a list with an input box and 'Go' button. I get the list value in my console but what I want is to iterate the list and enter the text (text is static) in the input box. Every time the list is selected it automatically searches rather than having to press the 'Go' button.  
WebElement search_list = driver.findElement(By.xpath("//*[@id='tl_tPlace']"));   
List <WebElement> li = search_list.findElements(By.tagName("option"));  
for(int i =0; i<li.size();i++){     
System.out.println(li.get(i).click());    
try{    
driver.findElement(By.xpath("//*@id='cmain_Place']")).sendKeys("text");

Now the first time the list has "select the state" it passes for the 2nd loop and it selects the list item. Once selected, the page reloads. Then there's an error message:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up


A: This is entirely expected behavior, since the DOM is completely recreated when the page, so any references you have to elements will become invalid after the page refreshes.
