Please comment the following code I found on YouTube. It checks whether an element is present at the time
public boolean isElementPresent(By locator)
{
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
List<WebElement> list = driver.findElements(locator);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
if (list.size() == 0)
return false;
else
return list.get(0).isDisplayed();
}
It dynamically changes implicitlyWait in the method. In all Selenium resources are always stated that the implicitWait can be set only once in the test class. The code above is similar to some extent to the explicit wait since it adapts to different situations. What is your opinion about this code?
In the Selenium documentation it is said that Once set, the implicit wait is set for the life of the session. However, in the code above we change the implicitlyWait twice. Is the documentation wrong?