The following piece of Python Selenium code do not work and I would be grateful for helping me to understand why.
It is designed to close pop-ups that block access to the account button. The number of pop-ups may vary. The idea is execute the while loop unless all the pop-ups are closed (the same function is to be called from other lines of the code as well), than the loop should be broken, so the program execution can continue. But it never does.
...
def check_popups(text):
while True:
try:
driver.find_element_by_class_name(text)
except NoSuchElementException:
break
else:
popup_close_button = driver.find_element_by_class_name("close_m")
popup_close_button.click()
...
check_popups("alert")
account_button = driver.find_element_by_class_name("lk_reg")
account_button.click()
P. S. Names for all classes are correct, they are not the suspects.