How to make Selenium WebDriver wait until combined expected condition?
Basically the similar question for Java has been asked and answered, but such method OR
(docs) isn't here for Python binding (expected_conditions.py on GitHub)
I have a very slow callback that results in one of the following:
- a div with id=
_report_success
if everything has been loaded correctly - a div with id=
_report_error
in case of any failure
So, I need to wait until either _report_success
or _report_error
becomes visible.
Separately these conditions are pretty straightforward:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, '_report_success')))
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, '_report_error')))
In Java the combined version looks like the following:
driverWait.until(ExpectedConditions.or(
ExpectedConditions.presenceOfElementLocated(...),
ExpectedConditions.presenceOfElementLocated(...)
));
Of course, I can make a loop and check the presence of both with an interval (actually like it's implemented in WebDriverWait.until), but I'm looking for more elegant and flexible solution. After all, if the method for such needs is present in Java version, why it's not in a Python binding?