ipStack
ipStack

Reputation: 426

How to wait element of a list is detroyed?

I want to click on all buttons in a table that delete their line :

    try:
        elements = driver.find_elements(By.XPATH, '//table//button[@class="deleteEntry"]')
    except NoSuchElementException:
        print("      [NoSuch] Buttons not found")
        return False

    for element in elements:        
        element.click()
        # How to wait element is destroyed ?

I must click on them one by one and wait one by one they are destroyed. I know to locate and click on them, but how do I to wait they are destroyed ?

Upvotes: 1

Views: 319

Answers (2)

jackblk
jackblk

Reputation: 1165

I assume that after you click the Delete button, some element will disappear (either going invisible or removed from DOM).

You can try Explicit wait.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# get the element here
# elem_to_disappear = ...

# click delete button
del_btn.click()

# wait until the element is gone
WebDriverWait(driver, 10).until(
    EC.invisibility_of_element(elem_to_disappear)
)

Futher document here: https://www.selenium.dev/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.expected_conditions.html#selenium.webdriver.support.expected_conditions.invisibility_of_element

Upvotes: 2

Erkin
Erkin

Reputation: 106

try driver.implicitly_wait(10) An implicit wait tells WebDriver to poll the DOM for a certain amount of time when trying to find any element (or elements) not immediately available.If it isnt work try time.sleep(waiting_time) from time library

Upvotes: 0

Related Questions