How to get selenium to wait for ajax response?
As we all like modern application BUT modern applications are not easy to test. When we are starting to write automation tests for application ajax based we ask ourself: How to get selenium to wait for ajax response?
So here one mistake can be made – to try to handle de situation by adding Thread.sleep(). You don’t want to do that – because basically hardcode the time to wait and your tests will fail on the second try.
Ajax wait for visual indicator
While the UI visually indicates that AJAX activity is occurring in this case you should be able to wait until such an indicator changes.
You can use:
You can see more details about ExpectedConditions class here . You can clearly see in the code that they handle both executions there NoSuchElementException and StaleElementReferenceException.
Ajax wait without visual indicator