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

14,787

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.

Share:
14,787
user3484831
Author by

user3484831

Updated on June 07, 2022

Comments

  • user3484831
    user3484831 almost 2 years

    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.

  • NarendraR
    NarendraR almost 7 years
    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.
  • Lukas Cenovsky
    Lukas Cenovsky almost 7 years
    I've added explanation how explicit wait works with implicit wait.