Silkking
Silkking

Reputation: 260

Wait until one element in list disappears

I have a table in which every row has a column with a checkbox. In case I uncheck it, it hides the row. I want to wait until this row disappears.

The things I've found are for when I have a concrete locator with EC.invisibility_of_element_located, but in this case, since are rows, every row has the same class and it doesn't make any sense to put an id to every row.

I would like to avoid something like time.sleep(2)

Thanks

Upvotes: 0

Views: 55

Answers (1)

JaSON
JaSON

Reputation: 4869

You can wait until the list count decreased by 1:

from selenium.webdriver.support.ui import WebDriverWait

_list = driver.find_elements_by_xpath('//tr')
list_count = len(_list)

WebDriverWait(driver, 10).until(lambda driver: len(driver.find_elements_by_xpath('//tr')) == list_count - 1)

This should work if row is physically deleted from DOM. In case it becomes hidden use something like driver.find_elements_by_xpath('//tr[not(@hidden)]') to locate visible rows

Upvotes: 1

Related Questions