0

I am automating a script to book appointments. Here is a snap of the datepicker. When available, dates are in green. datepicker

I can't know the attribute of the available dates until they are visible on the calendar. When available, they have no unique attribute to locate them with, they have a class and a title like unavailable dates and only the value changes.

<td class="day activeClass" title="Book">23</td>

I want to iterate all the dates, loop until i find available ones then select one of them.

After that comes the time of the appointment, which can be full even if the available date is in green. if an available time is there, i want to select it. If not, i want the script to go back to the available dates, select a different one then see if it has a available time. ( loop until time is available).

I started by locating the availables dates by Xpath, but i dont know how to do the rest.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
import sys

available_dates = driver.find_elements(By.XPATH, "//div[@class='datepicker-days']/table/tbody/tr/td[not(contains(@class, 'disabled'))]")

I think that the datepicker is handled by somekind of js code i found in the sources but i am unable to paste it here for you to see it. How can i use that js code to serve my purpose?( iterate dates, loop available dates and times)

Solved

  • what happens when you click on a green day? – sound wave Feb 06 '23 at 09:04
  • When you click on the green day, the website asks you to select a time ( a dropdown list) Then you continue to fill the form. Note that time is only visible after selecting an available day. Otherwise, you can't perform a thing – Elouali Issam Feb 06 '23 at 09:08
  • Here is the xpath of a free time slot i picked from another post `'//*[@id="slot_tr"]/td[2]'` – Elouali Issam Feb 06 '23 at 09:12
  • Since I cannot browse the site, can you share the html of the dropdown list? (edit the question and add the html) – sound wave Feb 06 '23 at 09:19
  • i cannot find the html of the time dropdown list because i need to find an available date first, select it the the dropdown list appears. all dates are unavailable now – Elouali Issam Feb 06 '23 at 09:30
  • wait i think i found it – Elouali Issam Feb 06 '23 at 09:32
  • @sound wave done – Elouali Issam Feb 06 '23 at 09:39
  • The html should contain also the list of all the values present in the dropdown list, can you share it too? – sound wave Feb 06 '23 at 10:47
  • They are no values . I think the values appear when the user select an available date. No available date no time available – Elouali Issam Feb 06 '23 at 10:50
  • You said "When you click on the green day, the website asks you to select a time (a dropdown list)" in order to help we need the full html of the dropdown list, and with "full" I mean also the html of all the elements contained inside the dropdown element. For example [look here](https://i.stack.imgur.com/weosM.png), you see there is the dropdown element `select` and all its children `option` which are the values that you can select in the dropdown. We need this full html – sound wave Feb 06 '23 at 10:57
  • I know i got your point. The problem is there are no available date at the moment. So i can't really triger the dropdown list to see its html without availability on the website – Elouali Issam Feb 06 '23 at 11:03
  • Ah ok sorry, so we have to wait. Meanwhile, do you already know if the dropdown is a `select` object or what you only see is the `input` object that you added in the question? – sound wave Feb 06 '23 at 11:09
  • Its a drop down list in which the user should select a timing plage exemple: 8:30 am to 10:30am / 11 :00 am to 12 : 00 am. You cannot type it manually inside the textbox – Elouali Issam Feb 06 '23 at 11:17
  • But i dont see the select word in the html of the list. This is confusing – Elouali Issam Feb 06 '23 at 11:20
  • `select` is not the only way to define a dropdown list, also `
    • ` can be used, or even just nested `
      `. So maybe that site doesn't use `select`
    – sound wave Feb 06 '23 at 11:45
  • Kinda lost here – Elouali Issam Feb 06 '23 at 12:00
  • guys can anyone else share something? – Elouali Issam Feb 06 '23 at 12:34
  • Anybody cares to help? – Elouali Issam Feb 06 '23 at 20:44
  • Are there available (green) dates now? – sound wave Feb 07 '23 at 08:07
  • no i check everyday everyhour nothing – Elouali Issam Feb 07 '23 at 08:18
  • Are you familiar with js? i found out that the dates are managed by a js code hidden somewhere . So i guess if i show you the js code, you should know what has to be done. – Elouali Issam Feb 07 '23 at 08:20
  • I'm not familiar with js, just used it few times, but add it in the question so that other users may help – sound wave Feb 07 '23 at 08:57
  • Does this answer your question? [Iterate dates in a datepicker to find available ones then select one of them](https://stackoverflow.com/questions/75385118/iterate-dates-in-a-datepicker-to-find-available-ones-then-select-one-of-them) – sound wave Feb 20 '23 at 13:19
  • @soundwave unfortunately no – Elouali Issam Feb 20 '23 at 13:34

0 Answers0