I'm trying to create an loop for searching a xpath in a page until is available.
I'm trying with this:
cart = driver.find_element_by_xpath('//*[@id="add-to-cart-button"]')
if not cart:
webdriver.ActionChains(driver).send_keys(Keys.F5).perform()
else:
driver.find_element_by_xpath('//*[@id="add-to-cart-button"]').click()
But is impossible to define cart because the xpath is not yet available.
How you do it?