Member-only story

Learn to Read the Documentation, Luke

Alex Siminiuc
2 min readOct 10, 2020

--

What is wrong in this Selenium code snippet?

public void waitUntilElementIsClickable(WebElement element)
{
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(element));
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}

At a first glance, the code seems correct.

The first line changes the timeout of the implicit wait to 0 so the implicit wait is disabled.

Then, an explicit wait and an expected condition are used for waiting until an element is clickable.

The last line changes the timeout of the implicit wait to 10 seconds so the implicit wait is enabled again.

At a second glance, lots of things are wrong.

To understand them, let’s read the following page from the Selenium documentation.

The page says the following about implicit waits:

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.

The default setting is 0, meaning disabled.

--

--

Alex Siminiuc
Alex Siminiuc

No responses yet