webdriver - Selecting list values automatically results in StaleElementReferenceException -


In my search page I have a list with an input box and a 'go' button. The value is received, but I want to iterate the list and enter the text in the input box (text is static) Every time when this list is selected, instead of pressing the 'go' button it automatically searches < / P> WebElement search_list = driver.findElement (By.xpath ("// * [@ id = 'tl_t place']"))); List & lt; WebElement & gt; Li = search_list.find Elements (By.tagName ("Options")); (Int i = 0; i & lt; li.size (); i ++) {System.out.println (li.get (i) .click ()); Try {driver.findElement (By.xpath ("// * @ id = 'cmain_Place']")))). SendKeys ("text");

Now for the first time in the list, select the "State" which passes it to the second loop and selects the list item. Once selected, the page reloads. Then there is an error message:

  Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: element in the cache was not found - perhaps the page has changed because it was viewed    

This is expected to behave completely, since DOM is completely built on the page, Elements will be invalid after reference page refresh.

Comments