I'm trying to write a while loop where if an element isn't found it does certain tasks, however when the element is not found, it throws an error NoSuchElementException as if there is no element, instead of going to the 'else' statement.
elem = driver.find_element_by_id('add-to-bag')
while True:
if elem.is_displayed():
False
else:
driver.delete_all_cookies()
driver.refresh()
sleep(randint(5, 10))