'How to select a class quickly, then stop when another id becomes present?
Using selenium, I'm trying to select a single instance of a class "reserve-time". Problem is, they become unavailable extremely quickly and so I'm hoping to immediately select the next "reserve-time" class in a list of many, until the presence of the id "book_time" appears.
This is as close as I've gotten:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
# wait for list to generate
reservetime = WebDriverWait(driver, 20, poll_frequency=0.1, ignored_exceptions=None)\
.until(ec.element_to_be_clickable((By.CLASS_NAME, "reserve-time")))
reservetime.click()
# if 'revervetime' clicked, continue to booktime
booktime = driver.find_element(By.XPATH, "//*[@id='book_time']/div/div[3]/button[1]")
This successfully selects and clicks the first "reserve-time" class on the site, but if it's no longer available, the script throws an exception and stops. How can I get it to try to select and click the next "reserve-time" class as quickly as possible, until the id "book_time" is present?
Any help is hugely appreciated. Thank you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
