Stale Element Reference Exception

I am getting the error of Stale element error Stale element Reference Exception, for the scrit which I have written. In the script I am getting error for… click element ${Xpath3} What I can try to avoid this error.

Adding Role 
          [Argument]       ${Role}
          input text                                           ${Xpath1}       ${Role}
          click element                                    ${Xpath2}
          wait until element is visible            ${Xpath3}
          click element                                    ${Xpath3}
          click element                                    ${Xpath4}

What version of selenium library do you use?
The exception is very common in selenium tests. And I think it is one of the reasons why people move to browser library, although it also had some timing issues.

A view suggestions:

  • adding a sleep before the failing keyword helps, buy it is inpractical for obvious reasons
  • setting implicit wait in selenium library might work
  • better check if you can upgrade to latest version of selenium library As stale elements is the most annoying error, there has been some magic tricks been implemented in later selenium versions
  • before those magic tricks, I believe I had success adding seleniumtestability library as plugin for selenium library. But I am not sure if that is still necessary nowadays

There are few tricks like using Wait until keyword succeeds but they are ugly and also as the error messages appeared at random in my test cases, I cannot verify what actually worked. All I can say, that after some updates, the error messages became rare.