The attached code will log on, go the Friday and then check if there is a available timeslot at 18:00(red is booked, grey is free). If the timeslot is free, then it should return the court number. At this moment he is not returning the court number, he is always going to the if not statement. I would like to get the number of the court if it’s available on given timeslot. With the code it’s possible to reproduce the steps, it would log on, go to the correct date, he should return a free court number,but at this moment he’s not returning the free court number. This is the code:
from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECimport timeimport sys# Bepaal Webdriverdriver = webdriver.Chrome() # Open de websitedriver.get("https://bent.baanreserveren.nl") # Tijd om scherm goed te stellentime.sleep(1)# START BOEKING 21:00 UUR# Vul Gebruikersnaam indriver.find_element(By.NAME, "username").send_keys("kbolk")# Vul Wachtwoord indriver.find_element(By.NAME, "password").send_keys("Test@123")# Klik op Inloggendriver.find_element(By.CSS_SELECTOR, ".form-submit3 > .button3").click()# Juiste dag (3x klikken)for _ in range(3): element = driver.find_element(By.CSS_SELECTOR, ".matrix-date-nav:nth-child(3)") element.click() time.sleep(1) # Selecteer Padel Buiten uit Dropdown lijstdropdown_element = driver.find_element(By.ID, "matrix-sport")dropdown_element.click()element = dropdown_element.find_element(By.XPATH, "//option[. = 'Padel Buiten']")element.click()dropdown_element = driver.find_element(By.ID, "matrix-sport")dropdown_element.click()time.sleep(1)court_preferences = ['3', '2', '4', '6', '7']booked = Falsefor court in court_preferences: available = driver.find_elements(By.XPATH, "//td[@type='free'][@title='Padel Buiten " + court +"'][./div[text()='18:00']]") print(available) if available: baan_boeking = court_preferences #here I would like to have the court number which is free print(baan_boeking) booked = Trueif not booked: print("No available courts found") sys.exit() # no courts availabe? No action needed, end of script# Here I would like to add the next steps if booked if true.print("Execute next steps")