Which selenium.webdriver.support.expected_conditions
are better to use when waiting for the invisibility of an element?
In my case, I input data into a form, click save and wait for a loader to disappear
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((SelectBy.CSS_SELECTOR, ".spinner")))
debug("loader appeared")
wait.until(EC.invisibility_of_element_located((SelectBy.CSS_SELECTOR, ".spinner")))
debug("loader disappeared")
In the output, I see that the second wait is executed for 20 seconds (my global implicit wait is 20 seconds)
360ms ⟥ [debug] loader appeared
21s 141ms ⟥ [debug] loader disappeared
The locator is good, I am trying to understand what is wrong with the wait. Did anyone have similar problems? I would be happy for any suggestions.
From the documentation of Waits
Warning: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example, setting an implicit wait of 10 seconds and an explicit wait of 15 seconds could cause a timeout to occur after 20 seconds.
Possibly the mix up of the following 2 waits:
is causing unpredictable wait times.
While inducing WebDriverWait you need to reconfigure implicit wait to 0
using the following line of code:
Python:
driver.implicitly_wait(0)
Java:
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
DotNet:
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(0);