Booking an Appointment using Selenium and Telebot in Python — Part 2

Amir Moradi
2 min readAug 24, 2020

There are different ways to find an element with selenium, including find by class_name, find by XPath and find by element’s id. As you can see in the picture above, for the email id element, its id is “EmailId”. I repeated this approach for the password and the captcha image. Finally, the “Continue” button is clicked to send inserted data.

At the end of update_captcha, the bot calls before_calendar function as an imported module. You can see its details here. In before_calendar, all steps of the booking process are done before checking the final calendar.

In one step of registration, a one-time password (OTP) is mailed automatically to the user’s email account. Two approaches have been defined to get OTP; 1) Appointment_Bot checks the user’s email account (just when the account is Gmail) and extracts OTP from unread messages of the user’s inbox; 2) The user checks manually his/her inbox and inserts OTP. Based on which way the user selects, otp_automate variables is set True or False.

In OTP extraction, sometimes the password is mailed lately and because it has a time limitation (around 3 minutes), the bot must click the Re-Generate OTP button, and check the inbox again. For each possible error that may happen, Appointment_Bot returns a message with proper content to inform the user of what happened.

Finally, when the bot reaches the final calendar, according to the inserted date by the user, it checks that date and if it is an open day, then select the date. Otherwise, it sends a message that the desired date is close, and no free appointment is available.

--

--

Amir Moradi

Ph.D. student | Passionate in Deep Learning, Reinforcement Learning, Image Processing, and Web Scraping for Data Analysis.