diff --git a/vfs_appointment_bot/vfs_bot/vfs_bot_de.py b/vfs_appointment_bot/vfs_bot/vfs_bot_de.py index 36a7172..246e26e 100644 --- a/vfs_appointment_bot/vfs_bot/vfs_bot_de.py +++ b/vfs_appointment_bot/vfs_bot/vfs_bot_de.py @@ -102,38 +102,72 @@ def check_for_appontment( """ page.get_by_role("button", name="Start New Booking").click() # Select Visa Centre - visa_centre_dropdown = page.locator("//mat-form-field/div/div/div[3]") + visa_centre_dropdown = page.wait_for_selector('mat-form-field') + + # Click on the mat-form-field to open the dropdown visa_centre_dropdown.click() - visa_centre_option = page.locator( - f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_center}')]" - ) - visa_centre_option.click() - - # Select Category - category_dropdown = page.locator("//div[@id='mat-select-value-3']") - category_dropdown.click() - category_option = page.locator( - f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_category}')]" - ) - category_option.click() - - # Select Subcategory - subcategory_dropdown = page.locator("//div[@id='mat-select-value-5']") - subcategory_dropdown.click() - subcategory_option = page.locator( - f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_sub_category}')]" - ) - subcategory_option.click() - - appointment_date_element = page.locator("//div[4]/div") - date_text = appointment_date_element.text - if ( - len(date_text) != 0 - and date_text != "No appointment slots are currently available" - and date_text - != "Currently No slots are available for selected category, please confirm waitlist\nTerms and Conditions" - ): - ts = time.time() - st = datetime.datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S") - return [f"message = {date_text} at {st}"] + + # Wait for the dropdown options to appear + page.wait_for_selector('mat-option') + + # Select the option by its text + visa_centre_dropdown_option = page.wait_for_selector('mat-option:has-text("New Delhi - Visa Application Centre")') + visa_centre_dropdown_option.click() + + # page.select_option('mat-option', label='New Delhi - Visa Application Centre') + # visa_centre_option = page.locator( + # f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_center}')]" + # ) + # visa_centre_option.click() + + # # Select Category + # category_dropdown = page.locator("//div[@id='mat-select-value-3']") + # category_dropdown.click() + # category_option = page.locator( + # f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_category}')]" + # ) + # category_option.click() + # Select Visa Category + visa_category_dropdown = page.query_selector_all('mat-form-field')[1] + + visa_category_dropdown.click() + + # Wait for the dropdown options to appear + page.wait_for_selector('mat-option') + + # Select the option by its text + visa_category_dropdown_option = page.wait_for_selector('mat-option:has-text("National Visa (stay of more than 90 days): Employment")') + visa_category_dropdown_option.click() + + # # Select Subcategory + # subcategory_dropdown = page.locator("//div[@id='mat-select-value-5']") + # subcategory_dropdown.click() + # subcategory_option = page.locator( + # f"//mat-option[starts-with(@id,'mat-option-')]/span[contains(text(), '{appointment_params.visa_sub_category}')]" + # ) + # subcategory_option.click() + visa_subcategory_dropdown = page.query_selector_all('mat-form-field')[2] + + visa_subcategory_dropdown.click() + + # Wait for the dropdown options to appear + page.wait_for_selector('mat-option') + + # Select the option by its text + visa_subcategory_dropdown_option = page.wait_for_selector('mat-option:has-text("Employment: any other employment (also vocational training)")') + visa_subcategory_dropdown_option.click() + try: + appointment_date_element = page.wait_for_selector("div.alert") + print(appointment_date_element) + date_text = appointment_date_element.text_content() + print(appointment_date_element.text_content()) + if ( + len(date_text) != 0 + ): + ts = time.time() + st = datetime.datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S") + return [f"message = {date_text} at {st}"] + except Exception as e: + print("Error '{0}' occured. Arguments {1}.".format(e.message, e.args)) + return None