Issue
Is there a way using which I can wait for one of two elements to get loaded in selenium. I am using explicit waits and so far, haven't been able to figure out the solution.
Simply doing
WebDriverWait(driver,5).until(lambda driver : driver.find_element(By.ID,"a") or driver.find_element(By.ID,"b"))
doesn't seem to work. It just looks for element with id ="a".
Thanks!
Solution
find_element
raises NoSuchElementException
exception if no element is found.
If element with the id a
does not exist, driver.find_element(By.ID,"a")
will raises the exception and the driver.find_element(By.ID,"b")
will not be executed.
A simple way to solve the problem is using find_elements
which return empty list instead of raising the exception:
WebDriverWait(driver,5).until(
lambda driver: driver.find_elements(By.ID,"a") or driver.find_elements(By.ID,"b"))
Answered By - falsetru
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.