dimanche 14 janvier 2018

Python Selenium While loop/if else statement

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 code 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))

Aucun commentaire:

Enregistrer un commentaire