Python v 3.12.0 Selenium v 4.17.2 Chrome v 121.0.6167.160 (Official Build) (arm64) Macbook Air OS v 14.2.1 (23C71)
Hi,
I'm new to Selenium and HTML. I'm trying to write short tennis court booking script against a generic site 'gotcourts.com' which homes the booking sheet of my tennis club. There is an image of the webpage below with the associated HTML code. There are 11 courts, the first eight of which are external courts and the final three are internal courts. External courts 5-8 are not open during the winter season so they are blocked out.
I'd like to identify an internal court by calendarRow (so I can get the right court) and title (so I can get the right time) and return the value of the class (so I can tell before sending a click, whether the court is already booked). Note the class changes depending the court is unavailable, booked or (by default) available.
I've spent quite a time looking at this but have not managed to work out how to do it. My nearest attempts are:
courts = driver.find_elements(By.XPATH,"//div[@class='calendarSlots']/div[@class='calendarSlotsForSport']/div[@class='calendarRow']/div[@title='15:00']") Which interestingly only has 7 elements (the calendarRows for out of service courts are not included - don't understand why)
courts = driver.find_element(By.XPATH,"//div[@class='calendarSlots']/div[@class='calendarSlotsForSport']/div[@class='calendarRow'][9]") courts2 = courts.find_element(By.CSS_SELECTOR,'[title="15:00"]') print("courts2: ",courts2) which prints an element:
courts2:
but when I change the print statement to:
print("courts2: ",courts2.get_attribute('innerHTML')) prints nothing. Many thanks for any guidance regarding what I should be writing to meet my goal, or hints what I have done wrong gratefully considered.

Источник: https://stackoverflow.com/questions/781 ... ng-seleniu