1

basically I am trying to loop driver.find_element_by_id("add-to-cart-button").click() so that it does this every 5 seconds even if it cannot find the element. All I have been able to put together is (there is more code but this is the base problem):

from selenium.common.exceptions import ElementNotVisibleException, WebDriverException, NoSuchElementException
import time
from selenium import webdriver

driver=webdriver.Chrome(executable_path="C:\webdrivers\chromedriver.exe")
driver.get("http://www.amazon.co.uk")

try:
    driver.find_element_by_id("add-to-cart-button").click()
except (ElementNotVisibleException, WebDriverException, NoSuchElementException):
    time.sleep(5)
    driver.find_element_by_id("add-to-cart-button").click()
  • 1
    Does this answer your question? [Selenium - wait until element is present, visible and interactable](https://stackoverflow.com/questions/59130200/selenium-wait-until-element-is-present-visible-and-interactable) – Erik McKelvey Jan 15 '22 at 00:33

0 Answers0