Consistent Selenium Testing in Python
FWIW the most consistent (as in non-flaky) selenium tests I&#x27;ve worked with used hidden DOM elements to synchronize the selenium driver with the JS code:<p><a href="http:&#x2F;&#x2F;www.draconianoverlord.com&#x2F;2011&#x2F;10&#x2F;14&#x2F;sane-selenium-testing.html" rel="nofollow">http:&#x2F;&#x2F;www.draconianoverlord.com&#x2F;2011&#x2F;10&#x2F;14&#x2F;sane-selenium-te...</a><p>Basically every JS ajax call (or JS promise, though we didn&#x27;t use any of those at the time) would update a hidden DOM element&#x27;s inner text, e.g. the `#pendingAjaxRequests` inner text would go to 1, or 2, then back to 0 when the AJAX response came back (ideally you do this instrumentation in a single place in your app).<p>Then on the selenium side, after every button click&#x2F;other action, we&#x27;d wait until those counters went back down to zero.<p>This post-action waiting (waiting for the app to &quot;settle&quot; after invoking actions) vs. pre-action waiting (...well, this the element I want to click on available yet? Hm...no...) was very reliable.