StaleElementException - After using navigate().back()



  • I'm trying to automate a testcase, where in there are around 30 links in a page. All these links will lead to a new page. And depending upon on a value in the new page, I need to either proceed or need to come back to the original page and re-select the link. This needs to be done until I find a particular value in the new page.

    So, I got a List of the links, then I started iterating, but as soon as I navigate back, either using driver.navigate().back() or another option and then try to find & click the next link, it hits StaleElementException.

    Any idea how I can handle this situation? Any help, code or approach wise would be highly appreciated!



  • When you return back to the page, page reloads and all elements become stale. For you it may look like same element (with same locator), but page is new object.

    So you need to fetch the elements again.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2