I am trying to refresh a webpage until a button exists and is enabled, when it is I want to click it.
I am trying the following:
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
# Initializing the browser driver (for example, Chrome)
driver = webdriver.Chrome('/path/to/chromedriver')
# Open the desired webpage
driver.get('https://www.example.com')
while True:
try:
# Find the button with the text "Buy"
reserve_button = driver.find_element_by_xpath('//button[contains(text(), "Buy")]')
# If the button is found, click on it
reserve_button.click()
print("The 'Buy' button is found and clicked.")
break # Exit the while loop if the button is found and clicked
except NoSuchElementException:
print("The 'Buy' button could not be found on the webpage. Page is being refreshed...")
# Refresh the page
driver.refresh()
# Quit the browser driver
driver.quit()
But the button is not found. Here is a copy of the element when inspecting the page.
Gereserveerd
How should I target the button?