A flaky Selenium test is one that passes and fails inconsistently without any change to the code being tested. Run it ten times and it might fail twice for no clear reason. Over time, these random failures quietly erode trust in test automation teams and start ignoring red builds, re-running suites "just in case," or disabling tests altogether instead of trusting the results.

What Causes Flaky Tests in Selenium?

Most flakiness traces back to a handful of recurring issues. Timing and synchronization problems top the list tests interact with elements before the page has finished loading.

Dynamic elements and unstable locators (like auto-generated IDs or layout-dependent XPath) break easily when the DOM shifts slightly. Shared test data and test-order dependency cause tests to pass or fail depending on what ran before them.

Environment differences between browser or WebDriver versions between CI and local machines introduce inconsistency, and running suites in parallel can create race conditions that only show up under load. Network latency or unstable third-party services add another layer of unpredictability outside the test's control.