QAAnywhere

Remote QA & testing jobs, worldwide.

Guides

Selenium waits explained: why tests fail before the page is ready

By Denis Bojkovski, Test Automation Architect · Published November 25, 2026

The race behind most UI failures

Your test and the browser run independently. A click starts a request; the next line of the test runs before the response arrives. Selenium was named by 21 of 236 remote roles on QAAnywhere on 25 November 2026, and waiting correctly is the skill that separates a stable Selenium suite from one nobody trusts.

Three kinds of wait

Implicit wait tells the driver to keep looking for a missing element for some time. It applies to every lookup. It knows about presence only: an element that exists but is hidden counts as found.

Explicit wait waits for one condition at one point. It is the one to use.

Fluent wait is an explicit wait with a custom interval and ignored exceptions. In .NET, WebDriverWait already allows both.

Do not combine implicit and explicit waits. Selenium's documentation warns that mixing them causes unpredictable wait times.

Wait for the outcome

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

driver.FindElement(By.Id("save")).Click();

var message = wait.Until(d =>
{
    var found = d.FindElements(By.CssSelector("[role=status]")).FirstOrDefault();
    return found is { Displayed: true } && found.Text.Length > 0 ? found : null;
});

Assert.That(message!.Text, Is.EqualTo("Saved"));

The lambda returns null until the element is visible and has text. FindElements returns an empty list instead of throwing, so there is no exception to catch. Waiting for "some text" and then asserting gives a better failure message than waiting for the exact text and timing out.

Conditions worth knowing

  • A spinner has gone and the result is present. The spinner may not have appeared yet, so its absence alone proves nothing.
  • A button is enabled, not only visible.
  • The number of rows equals the expected count.
  • The URL has changed.
  • A custom attribute set by the application, for example data-loaded="true". Asking developers for one signal is cheaper than guessing from animations.

Stale element references

StaleElementReferenceException means the element you hold was removed or re-rendered. The fix is to look it up again, not to retry the same object:

void ClickFresh(By by) => wait.Until(d =>
{
    try { d.FindElement(by).Click(); return true; }
    catch (StaleElementReferenceException) { return false; }
});

Use this where the page is known to re-render. Applied everywhere, it can repeat an action that had already worked. Never wrap a payment button in a blind retry.

Replacing sleeps

Search the suite for Thread.Sleep. For each one ask what it waits for:

  1. Something on screen: use an explicit wait.
  2. A background job: poll an API or the database with a limit.
  3. An animation: turn animations off in the test environment.
  4. Nobody remembers: remove it and run the test fifty times.

A five-second sleep in two hundred tests costs nearly seventeen minutes of serial time, and still fails on the day the server takes six.

Choosing a timeout

A long timeout does not slow passing tests, since the wait ends as soon as the condition holds. It slows failing ones. Ten seconds is a sensible default for a test environment. If one action needs sixty, give that action its own wait and raise the performance with the team.

Further reading

When failures remain after the waits are right, look at data and environment: flaky tests in CI covers the method. For running the suite on many browsers, see Selenium Grid and parallel runs.

Open remote QA roles that use Selenium

  1. Manual QA Engineer (Game Client)Playson · Europe
  2. Senior/Mid QA Engineer - (AEM) - 3 Months (Extendable)Robusta · Remote, Cairo, Cairo Governorate, Egypt
  3. Principal Software Engineer in TestNatera · Remote
  4. Senior SDETYipitData · India Remote
  5. Senior QA Engineer IPrenuvo · Remote, USA

More guides