1

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 ?

ipStack
  • 381
  • 1
  • 12

2 Answers2

2

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

jackblk
  • 1,076
  • 8
  • 19
  • Check the problem I had when I used `invisibility_of_element_located` with implicit wait https://stackoverflow.com/questions/65373501/why-does-seleniums-wait-until-notec-invisibility-of-element-located-does-not It is better to avoid uding implicit wait at of if you are using `invisibility_of_element` and `invisibility_of_element_located` – vitaliis Apr 09 '21 at 12:12
0

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

Erkin
  • 96
  • 1
  • 5