I'm trying to search for an element and if it doesn't exist search for another element, and here is my code:
try:
elem1 = driver.find_element_by_xpath('xpath1')
elem = driver.find_element_by_xpath("xpath2")
if elem.is_displayed():
print('found 1st element')
driver.quit()
elif elem1.is_displayed():
print('found 2nd element')
driver.quit()
except NoSuchElementException:
driver.quit()
print('Error!')
but every time I get 'Error!', but when i try to find only one of the two elements it works properly.