Member-only story

Why do you need Selenium Explicit Waits and Expected Conditions?

Alex Siminiuc
4 min readFeb 29, 2020

--

Photo by NordWood Themes on Unsplash

I was teaching a few weeks ago a group of testers about how their Selenium tests should be synchronized with the site.

This synchronization is essential since, without it, the tests run well if the site is fast but fail if the site is slow.

The loading time of the site depends on many factors that are outside of our control such as network speed and bandwidth, performance of the hosting servers, the application or the number of concurrent users.

The syntax of the synchronization mechanism is pretty verbose and complicated in C#:

//wait until the page is displayed
TimeSpan timeout = TimeSpan.FromSeconds(30)
WebDriverWait wait = new WebDriverWait(driver, timeout);wait.Until(d =>
{ return d.Url.Contains(“vpl.ca”) &&
d.Title.Contains(“Vancouver Public Library”);
});
//interact with the page

or

//wait until the element is found and enabled
TimeSpan timeout = TimeSpan.FromSeconds(30);
WebDriverWait wait = new WebDriverWait(driver, timeout);wait.Until(d =>
{
return d.FindElement(searchBoxId).Enabled;
});

--

--

Alex Siminiuc
Alex Siminiuc

No responses yet