As falsetru explained if your first find_element
call fails to find an element, it will raise NoSuchElementException
and the 2nd part of your test won't execute.
I would suggest using a CSS selector that matches either IDs you are looking for:
WebDriverWait(driver, 5).until(
lambda driver : driver.find_element_by_css_selector("#a, #b"))
This has an advantage over performing two find_elements
calls becayse this will make only one roundtrip between your Selenium client (your script) and the Selenium server. This should always be faster than performing two find_elements
calls. When performing tests locally, the difference won't be much but if you perform tests remotely, for instance using Sauce Labs or Browser Stack, the difference will be significant.
while True
" loop waiting for half a second each cycle. – Arnie