ExpectedCondition.invisibility_of_element_located takes more time (selenium web driver-python)
Asked Answered
A

3

6

I am using below ExpectedCondition method to ensure that element disappears and my test proceeds after that

wait.until(EC.invisibility_of_element_located((By.XPATH,busyIndicator)))

What I am doing is click on save button. It will show busyindicator object. Once Save operation is done busy indicator disappears to indicate save operation is done.

Here, though busyindicator object disappears quickly from UI, but still my above webdriver command takes almost 30-40 seconds to ensure this element is removed.

Need help on 1) How to optimize above code so that it gets executed quickly 2) Other better way to ensure elements disappears.

Antony answered 24/7, 2014 at 8:24 Comment(1)
have you found solution for this problem?Laughry
D
9

Make sure you don't have set up implicit timeout or set it to 0 before waiting:

driver.implicitly_wait(0)
WebDriverWait(driver, 30).until(EC.invisibility_of_element_located((By.XPATH,busyIndicator)))

Implicit timeout applies to any command, that is also to _find_element used by WebDriverWait.

In your case, busy indicator is probably removed from DOM. Explicit wait for invisibility calls find_element. As the element is not in DOM, it takes implicit timeout to complete. If you have implicit wait 30s, it will take 30s. And only then explicit wait finishes successfully. Add time for which the busy indicator is visible and you are on your 30-40 seconds.

Dharma answered 31/7, 2017 at 15:41 Comment(2)
Is it really the issue to use explicit and implicit wait both ?, because there are lots of element which require some time to interact lets say withing 10 second but there is one element lets say its the page loader for which i have to use explicit wait for its invisibility once get invisible then only i have to interact other page element.Ohmmeter
I've added explanation how explicit wait works with implicit wait.Dharma
K
0

Specifying a decent wait time that webDriver checks for the visibility can be a FluentWait or Low ExplicityWait. Below are Java Snippet I reckon it will give you an idea on how to implement on other bindings. hope this helps

      //Specify any less time
      WebDriverWait wait = new WebDriverWait(driver, 5);
      WebElement element = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id('id')));

      //FluentWait
      Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
     .withTimeout(10, SECONDS)
     .pollingEvery(5, SECONDS)
     .ignoring(NoSuchElementException.class);

      WebElement element = wait.until(new Function<WebDriver, WebElement>() {
      public WebElement apply(WebDriver driver) {
      return driver.findElement(By.id("someid"));
   } 
});
Klaxon answered 24/7, 2014 at 9:19 Comment(0)
W
0

You should set implicitly_wait to 1 second before calling the code. I recommend you to create a new function to use this specific implicitly_wait there.

     def wait_for_spinner(driver):
        driver.implicitly_wait(1)
        wait.until(EC.invisibility_of_element_located((By.XPATH,busyIndicator)))
Waver answered 26/4, 2023 at 20:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.