I'm using Python Selenium to fill a form. When I click a button like this:
Button = driver.find_element(By.XPATH, '//*[@id="root"]/div[1]/form/button')
Button.click()
img_wait = WebDriverWait(driver, timeout).until(EC.visibility_of_all_elements_located((By.CLASS_NAME, "image")))
img = driver.find_elements(By.CLASS_NAME, "image")
What happens is that sometimes the website doesn't process the request correctly and opens up a modal with an error message (CLASS_NAME "alert")
.
What I would like to do is, while waiting for the class "image" to load, if any element with class "alert" gets loaded by the page, hit the button again. Otherwise just keep waiting (I have a timeout exception anyway at the end).